Fix exec_command to hang indefinitely

Execution `recv_exit_status` before reading from channel may cause it hang
indefinitely.

Change-Id: I24dd3802133509f250659582ffb7d7f759e80988
Closes-Bug: #1615659
This commit is contained in:
Georgy Dyuldin 2016-08-22 15:28:46 +03:00
parent 3d8118bee9
commit bce51c53a0
1 changed files with 2 additions and 1 deletions

View File

@ -121,7 +121,6 @@ class Client(object):
channel.fileno() # Register event pipe
channel.exec_command(cmd)
channel.shutdown_write()
exit_status = channel.recv_exit_status()
# If the executing host is linux-based, poll the channel
if self._can_system_poll():
@ -162,6 +161,8 @@ class Client(object):
out_data = out_data.decode(encoding)
err_data = err_data.decode(encoding)
exit_status = channel.recv_exit_status()
if 0 != exit_status:
raise exceptions.SSHExecCommandFailed(
command=cmd, exit_status=exit_status,