{"action":"created","issue":{"url":"https://api.github.com/repos/paramiko/paramiko/issues/380","labels_url":"https://api.github.com/repos/paramiko/paramiko/issues/380/labels{/name}","comments_url":"https://api.github.com/repos/paramiko/paramiko/issues/380/comments","events_url":"https://api.github.com/repos/paramiko/paramiko/issues/380/events","html_url":"https://github.com/paramiko/paramiko/issues/380","id":40987719,"number":380,"title":"Packet.read_all() hangs on socket.recv() when transport is closed by different thread","user":{"login":"GMTA","id":3210731,"avatar_url":"https://avatars.githubusercontent.com/u/3210731?v=3","gravatar_id":"","url":"https://api.github.com/users/GMTA","html_url":"https://github.com/GMTA","followers_url":"https://api.github.com/users/GMTA/followers","following_url":"https://api.github.com/users/GMTA/following{/other_user}","gists_url":"https://api.github.com/users/GMTA/gists{/gist_id}","starred_url":"https://api.github.com/users/GMTA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GMTA/subscriptions","organizations_url":"https://api.github.com/users/GMTA/orgs","repos_url":"https://api.github.com/users/GMTA/repos","events_url":"https://api.github.com/users/GMTA/events{/privacy}","received_events_url":"https://api.github.com/users/GMTA/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/paramiko/paramiko/labels/Bug","name":"Bug","color":"a04040"},{"url":"https://api.github.com/repos/paramiko/paramiko/labels/Needs%20investigation","name":"Needs investigation","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-08-23T22:50:50Z","updated_at":"2015-05-13T02:03:33Z","closed_at":null,"body":"I'm developing a FUSE library using Paramiko as an SSH client backend (see https://github.com/GMTA/mountload). FUSE can optionally run daemonized (foreground=False). I discovered that whenever I run FUSE as a daemon and directly unmount the mounted filesystem, Paramiko fails to close its SFTPClient causing the process to hang indefinitely.\r\n\r\nI did some research and I discovered that the main difference between running FUSE as a daemon and in the foreground is that the construction and destruction happens in different threads when daemonized.\r\n\r\nSo what happens in this different thread?\r\n- I close the SSHClient by calling .close()\r\n- SSHClient.close() calls self._transport.close()\r\n- Transport.close() calls self.stop_thread()\r\n- Transport.stop_Thread() keeps looping on self.isAlive() and self.join(10)\r\n\r\nApparantly, Transport.run() is running indefinitely:\r\n- Transport.run() calls self.packetizer.read_message()\r\n- Packet.read_message() calls Packet.read_all()\r\n- Packet.read_all() calls self.__socket.recv()\r\n\r\nI added additional logging directly before and after this recv() call (and every possible **except**, even an additional **finally**) and it looks like recv() never returns. I tried replacing it with select.select(), but to no avail. I added socket.shutdown() in the Packet.close() method, but this did not help.\r\n\r\nI find it quite odd that Transport itself always runs another thread, so it should not matter which thread calls the Transport.stop_thread() method..."},"comment":{"url":"https://api.github.com/repos/paramiko/paramiko/issues/comments/101482233","html_url":"https://github.com/paramiko/paramiko/issues/380#issuecomment-101482233","issue_url":"https://api.github.com/repos/paramiko/paramiko/issues/380","id":101482233,"user":{"login":"rustyscottweber","id":4672283,"avatar_url":"https://avatars.githubusercontent.com/u/4672283?v=3","gravatar_id":"","url":"https://api.github.com/users/rustyscottweber","html_url":"https://github.com/rustyscottweber","followers_url":"https://api.github.com/users/rustyscottweber/followers","following_url":"https://api.github.com/users/rustyscottweber/following{/other_user}","gists_url":"https://api.github.com/users/rustyscottweber/gists{/gist_id}","starred_url":"https://api.github.com/users/rustyscottweber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rustyscottweber/subscriptions","organizations_url":"https://api.github.com/users/rustyscottweber/orgs","repos_url":"https://api.github.com/users/rustyscottweber/repos","events_url":"https://api.github.com/users/rustyscottweber/events{/privacy}","received_events_url":"https://api.github.com/users/rustyscottweber/received_events","type":"User","site_admin":false},"created_at":"2015-05-13T02:03:33Z","updated_at":"2015-05-13T02:03:33Z","body":"+1 for this problem. Attempting some debugging but it would appear totally blocked on the read from the socket which never returns."}}