{"action":"opened","issue":{"url":"https://api.github.com/repos/pkg/sftp/issues/42","labels_url":"https://api.github.com/repos/pkg/sftp/issues/42/labels{/name}","comments_url":"https://api.github.com/repos/pkg/sftp/issues/42/comments","events_url":"https://api.github.com/repos/pkg/sftp/issues/42/events","html_url":"https://github.com/pkg/sftp/issues/42","id":87396212,"number":42,"title":"client.Close hangs on channel recvClosed","user":{"login":"rlmcpherson","id":1706273,"avatar_url":"https://avatars.githubusercontent.com/u/1706273?v=3","gravatar_id":"","url":"https://api.github.com/users/rlmcpherson","html_url":"https://github.com/rlmcpherson","followers_url":"https://api.github.com/users/rlmcpherson/followers","following_url":"https://api.github.com/users/rlmcpherson/following{/other_user}","gists_url":"https://api.github.com/users/rlmcpherson/gists{/gist_id}","starred_url":"https://api.github.com/users/rlmcpherson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlmcpherson/subscriptions","organizations_url":"https://api.github.com/users/rlmcpherson/orgs","repos_url":"https://api.github.com/users/rlmcpherson/repos","events_url":"https://api.github.com/users/rlmcpherson/events{/privacy}","received_events_url":"https://api.github.com/users/rlmcpherson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-11T16:04:38Z","updated_at":"2015-06-11T16:04:38Z","closed_at":null,"body":"When closing clients that are accessed concurrently from multiple goroutines, the client `Close()` method hangs waiting on a receive from c.recvClosed. This started occurring when a change was made in the client code to use clients concurrently from more than one goroutine. I suspect there is a deadlock occurring in the client `recv()` function, since this is the only  function that closes the `c.recvClosed` channel. Requests may still be in progress when client `Close` is called, but this shouldn't cause the method to block indefinitely. I think the `Close()` method may need a way to cancel inflight requests. I'm happy to take a stab at a PR or do additional debugging on this but if anyone with more familiarity with the sftp package code  can comment on why this is occurring I'd appreciate it. \r\n\r\npartial stacktrace showing blocking on `recvClosed`:\r\n```\r\ngoroutine 5 [chan receive, 1013 minutes]:\r\ngithub.com/pkg/sftp.(*Client).Close(0xc25d62f590, 0x0, 0x0)\r\n        /Users/rmcpherson/dev/go/src/github.com/pkg/sftp/client.go:100 +0x8d\r\ngithub.com/codeguard/lister/client.(*SftpClient).Close(0xc208945e60, 0x0, 0x0)\r\n```\r\n"}}