{"action":"created","issue":{"url":"https://api.github.com/repos/paramiko/paramiko/issues/448","labels_url":"https://api.github.com/repos/paramiko/paramiko/issues/448/labels{/name}","comments_url":"https://api.github.com/repos/paramiko/paramiko/issues/448/comments","events_url":"https://api.github.com/repos/paramiko/paramiko/issues/448/events","html_url":"https://github.com/paramiko/paramiko/issues/448","id":50096163,"number":448,"title":"channel.recv_exit_status() hanging","user":{"login":"kprantis","id":1007568,"avatar_url":"https://avatars.githubusercontent.com/u/1007568?v=3","gravatar_id":"","url":"https://api.github.com/users/kprantis","html_url":"https://github.com/kprantis","followers_url":"https://api.github.com/users/kprantis/followers","following_url":"https://api.github.com/users/kprantis/following{/other_user}","gists_url":"https://api.github.com/users/kprantis/gists{/gist_id}","starred_url":"https://api.github.com/users/kprantis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kprantis/subscriptions","organizations_url":"https://api.github.com/users/kprantis/orgs","repos_url":"https://api.github.com/users/kprantis/repos","events_url":"https://api.github.com/users/kprantis/events{/privacy}","received_events_url":"https://api.github.com/users/kprantis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/paramiko/paramiko/milestones/9","html_url":"https://github.com/paramiko/paramiko/milestones/1.16.1","labels_url":"https://api.github.com/repos/paramiko/paramiko/milestones/9/labels","id":1400546,"number":9,"title":"1.16.1","description":null,"creator":{"login":"bitprophet","id":6088,"avatar_url":"https://avatars.githubusercontent.com/u/6088?v=3","gravatar_id":"","url":"https://api.github.com/users/bitprophet","html_url":"https://github.com/bitprophet","followers_url":"https://api.github.com/users/bitprophet/followers","following_url":"https://api.github.com/users/bitprophet/following{/other_user}","gists_url":"https://api.github.com/users/bitprophet/gists{/gist_id}","starred_url":"https://api.github.com/users/bitprophet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitprophet/subscriptions","organizations_url":"https://api.github.com/users/bitprophet/orgs","repos_url":"https://api.github.com/users/bitprophet/repos","events_url":"https://api.github.com/users/bitprophet/events{/privacy}","received_events_url":"https://api.github.com/users/bitprophet/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":0,"state":"open","created_at":"2015-11-09T01:13:24Z","updated_at":"2015-12-06T19:40:16Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2014-11-25T22:59:13Z","updated_at":"2015-12-06T20:46:55Z","closed_at":null,"body":"We are seeing channel.recv_exit_status() hanging seemingly indefinitely in certain cases. From some minor testing, it seems related to the size of the output returned. \r\n\r\nConsider the script below, when NUM_LOOPS=3500, the command executes just fine, and in only about ~1 second. But If I increase it to 4000, then it just hangs indefinitely. The number it hangs on appears to vary with the size of the output (aka, I can get to at least 10k if I echo 'banana' instead). Of course, this could all be a red herring, but thought I'd include it in case relevant.\r\n\r\n```\r\nimport logging\r\nimport socket\r\nimport time\r\nimport paramiko\r\nimport re\r\n\r\n\r\ndef _ssh_address(address, command, timeout=30):\r\n    \"\"\"\r\n    Executes a command on a remote server over ssh.\r\n\r\n    Sends a command over ssh to a remote machine and returns the stdout,\r\n    stderr, and exit status. It will verify that the exit status of the\r\n    command matches expected_return_code unless expected_return_code=None.\r\n    \"\"\"\r\n    print \"remote_command[%s]: %s\" % (address, command)\r\n    ssh = paramiko.SSHClient()\r\n    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())\r\n\r\n    args = {'username': 'root'}\r\n    print \"SSH address = %s, args = %s\" % (address, args)\r\n\r\n    ssh.connect(address, **args)\r\n    transport = ssh.get_transport()\r\n    transport.set_keepalive(20)\r\n    channel = transport.open_session()\r\n    channel.settimeout(timeout)\r\n    channel.exec_command(command)\r\n    print \"exec_command\"\r\n    exit_status = channel.recv_exit_status()  # Blocks until command succeeds\r\n    print \"recv_exit_status\"\r\n    stdout = channel.makefile('rb').read()  # Be sure to read before the channel closes\r\n    print \"stdout\"\r\n    stderr = channel.makefile_stderr('rb').read()\r\n    print \"stderr\"\r\n    channel.close()\r\n    print \"closed\"\r\n    return (exit_status, stdout, stderr)\r\n\r\nif __name__ == '__main__':\r\n    NUM_LOOPS=4000\r\n    exit_status, stdout, stderr = _ssh_address('lotus-33vm15', 'for i in {1..%s}; do echo \"Some random output from a command.\"; done' % NUM_LOOPS)\r\n    print \"Exit status %s\" % exit_status\r\n    print \"stdout %s\" % stdout\r\n    print \"stderr %s\" % stderr\r\n```\r\n\r\nparamiko version is 1.7.5"},"comment":{"url":"https://api.github.com/repos/paramiko/paramiko/issues/comments/162346200","html_url":"https://github.com/paramiko/paramiko/issues/448#issuecomment-162346200","issue_url":"https://api.github.com/repos/paramiko/paramiko/issues/448","id":162346200,"user":{"login":"bitprophet","id":6088,"avatar_url":"https://avatars.githubusercontent.com/u/6088?v=3","gravatar_id":"","url":"https://api.github.com/users/bitprophet","html_url":"https://github.com/bitprophet","followers_url":"https://api.github.com/users/bitprophet/followers","following_url":"https://api.github.com/users/bitprophet/following{/other_user}","gists_url":"https://api.github.com/users/bitprophet/gists{/gist_id}","starred_url":"https://api.github.com/users/bitprophet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitprophet/subscriptions","organizations_url":"https://api.github.com/users/bitprophet/orgs","repos_url":"https://api.github.com/users/bitprophet/repos","events_url":"https://api.github.com/users/bitprophet/events{/privacy}","received_events_url":"https://api.github.com/users/bitprophet/received_events","type":"User","site_admin":false},"created_at":"2015-12-06T20:46:55Z","updated_at":"2015-12-06T20:46:55Z","body":"Actually, I can confirm/deny the relationship to that window size variable by supplying a larger/smaller value to `myclient.get_transport().default_window_size` (as of 1.15 and up). Setting it much smaller makes the hang much sooner, setting it much larger, conversely likewise.\r\n\r\nI still don't know enough about the details to know *why* this is happening but it makes me lean more towards \"actual bug\". But I've got other work I gotta do so still gonna slap the warning on here for now =/"}}