{"action":"created","issue":{"url":"https://api.github.com/repos/restify/node-restify/issues/642","labels_url":"https://api.github.com/repos/restify/node-restify/issues/642/labels{/name}","comments_url":"https://api.github.com/repos/restify/node-restify/issues/642/comments","events_url":"https://api.github.com/repos/restify/node-restify/issues/642/events","html_url":"https://github.com/restify/node-restify/issues/642","id":37830039,"number":642,"title":"httpclient.close() isn't really safe","user":{"login":"davepacheco","id":532688,"avatar_url":"https://avatars.githubusercontent.com/u/532688?v=3","gravatar_id":"","url":"https://api.github.com/users/davepacheco","html_url":"https://github.com/davepacheco","followers_url":"https://api.github.com/users/davepacheco/followers","following_url":"https://api.github.com/users/davepacheco/following{/other_user}","gists_url":"https://api.github.com/users/davepacheco/gists{/gist_id}","starred_url":"https://api.github.com/users/davepacheco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davepacheco/subscriptions","organizations_url":"https://api.github.com/users/davepacheco/orgs","repos_url":"https://api.github.com/users/davepacheco/repos","events_url":"https://api.github.com/users/davepacheco/events{/privacy}","received_events_url":"https://api.github.com/users/davepacheco/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/restify/node-restify/labels/bug","name":"bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-07-14T21:29:00Z","updated_at":"2015-06-29T04:10:28Z","closed_at":null,"body":"HttpClient.close() reaches into the Node agent and calls end() on all of the sockets in use by the agent.  It doesn't check that the socket's remote address matches the server that the client was created with.  More importantly, though, the Node documentation says not to touch these sockets, and the problem with doing this is that if you call client.close() and then try to make another request (with a different client or even outside restify, AFAICT), the Node agent may decide to use one of the sockets that has started closing, and it will immediately get a \"socket hang up\" error.\r\n\r\nI don't think there's a great way to implement close() given the current agent API, but what restify's doing right now makes it possible to run into bugs like node-manta#194.  If the point of close() is basically for command-line programs to wrap things up, then it should probably be a global function (i.e., not per-agent), since it's closing everything, and it probably needs to be provided by the agent implementation."},"comment":{"url":"https://api.github.com/repos/restify/node-restify/issues/comments/116427984","html_url":"https://github.com/restify/node-restify/issues/642#issuecomment-116427984","issue_url":"https://api.github.com/repos/restify/node-restify/issues/642","id":116427984,"user":{"login":"micahr","id":111574,"avatar_url":"https://avatars.githubusercontent.com/u/111574?v=3","gravatar_id":"","url":"https://api.github.com/users/micahr","html_url":"https://github.com/micahr","followers_url":"https://api.github.com/users/micahr/followers","following_url":"https://api.github.com/users/micahr/following{/other_user}","gists_url":"https://api.github.com/users/micahr/gists{/gist_id}","starred_url":"https://api.github.com/users/micahr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micahr/subscriptions","organizations_url":"https://api.github.com/users/micahr/orgs","repos_url":"https://api.github.com/users/micahr/repos","events_url":"https://api.github.com/users/micahr/events{/privacy}","received_events_url":"https://api.github.com/users/micahr/received_events","type":"User","site_admin":false},"created_at":"2015-06-29T04:10:28Z","updated_at":"2015-06-29T04:10:28Z","body":"Definitely can cause some unexpected behavior. Thanks for reporting it Dave. We should probably just remove the close method from the Http Client as a user could call the method expecting it to act only on their client instance, not across all sockets for the agent."}}