{"action":"created","issue":{"url":"https://api.github.com/repos/xetorthio/jedis/issues/847","labels_url":"https://api.github.com/repos/xetorthio/jedis/issues/847/labels{/name}","comments_url":"https://api.github.com/repos/xetorthio/jedis/issues/847/comments","events_url":"https://api.github.com/repos/xetorthio/jedis/issues/847/events","html_url":"https://github.com/xetorthio/jedis/issues/847","id":53820737,"number":847,"title":"Possible resource leak in disconnect()","user":{"login":"allanwax","id":8459774,"avatar_url":"https://avatars.githubusercontent.com/u/8459774?v=3","gravatar_id":"","url":"https://api.github.com/users/allanwax","html_url":"https://github.com/allanwax","followers_url":"https://api.github.com/users/allanwax/followers","following_url":"https://api.github.com/users/allanwax/following{/other_user}","gists_url":"https://api.github.com/users/allanwax/gists{/gist_id}","starred_url":"https://api.github.com/users/allanwax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allanwax/subscriptions","organizations_url":"https://api.github.com/users/allanwax/orgs","repos_url":"https://api.github.com/users/allanwax/repos","events_url":"https://api.github.com/users/allanwax/events{/privacy}","received_events_url":"https://api.github.com/users/allanwax/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-09T00:43:10Z","updated_at":"2015-01-09T01:29:18Z","closed_at":null,"body":"In `Connection`\r\n\r\n```java\r\n\tpublic void disconnect() {\r\n\t\tif (isConnected()) {\r\n\t\t\ttry {\r\n\t\t\t\tinputStream.close();\r\n\t\t\t\tif (!socket.isClosed()) {\r\n\t\t\t\t\toutputStream.close();\r\n\t\t\t\t\tsocket.close();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tcatch (IOException ex) {\r\n\t\t\t\tbroken = true;\r\n\t\t\t\tthrow new JedisConnectionException(ex);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n```\r\n\r\nIf either `inputStream` or `outputStream` fails during close, the socket is never closed.  Sockets are one of the few things that if they are not closed the kernel will keep them 'open' and deny reuse of the resource.\r\n\r\nBetter would be separate `try ... catch` clauses which will eventually get to closing the socket."},"comment":{"url":"https://api.github.com/repos/xetorthio/jedis/issues/comments/69280607","html_url":"https://github.com/xetorthio/jedis/issues/847#issuecomment-69280607","issue_url":"https://api.github.com/repos/xetorthio/jedis/issues/847","id":69280607,"user":{"login":"allanwax","id":8459774,"avatar_url":"https://avatars.githubusercontent.com/u/8459774?v=3","gravatar_id":"","url":"https://api.github.com/users/allanwax","html_url":"https://github.com/allanwax","followers_url":"https://api.github.com/users/allanwax/followers","following_url":"https://api.github.com/users/allanwax/following{/other_user}","gists_url":"https://api.github.com/users/allanwax/gists{/gist_id}","starred_url":"https://api.github.com/users/allanwax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allanwax/subscriptions","organizations_url":"https://api.github.com/users/allanwax/orgs","repos_url":"https://api.github.com/users/allanwax/repos","events_url":"https://api.github.com/users/allanwax/events{/privacy}","received_events_url":"https://api.github.com/users/allanwax/received_events","type":"User","site_admin":false},"created_at":"2015-01-09T01:29:18Z","updated_at":"2015-01-09T01:29:18Z","body":"Something like this.  apologies, I just quickly scrathed this out.\r\n\r\n```java\r\npublic void disconnect() {\r\n\t\tif (isConnected()) {\r\n\t\t\ttry {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tinputStream.close();\r\n\t\t\t\t}\r\n\t\t\t\tcatch (IOException ex) {\r\n\t\t\t\t\tbroken = true;\r\n\t\t\t\t\tthrow new JedisConnectionException(ex);\r\n\t\t\t\t}\r\n\t\t\t\tfinally {\r\n\t\t\t\t\tif (!socket.isClosed()) {\r\n\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\toutputStream.close();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (Exception e2) {\r\n\t\t\t\t\t\t\tbroken = true;\r\n\t\t\t\t\t\t\tthrow new JedisConnectionException(e2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tcatch (Exception ex) {\r\n\t\t\t\tbroken = true;\r\n\t\t\t\tthrow new JedisConnectionException(ex);\r\n\t\t\t}\r\n\t\t\tfinally {\r\n\t\t\t\tif (!socket.isClosed()) {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\tsocket.close();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcatch (Exception e1) {\r\n\t\t\t\t\t\tbroken = true;\r\n\t\t\t\t\t\tthrow new JedisConnectionException(e1);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n```\r\n"}}