Paramiko uses 100% CPU with ProxyCommand #413

Closed
jasondunsmore opened this Issue Oct 2, 2014 · 2 comments

Projects

None yet

2 participants

@jasondunsmore

Using a ProxyCommand socket to execute a command over SSH results in 100% CPU usage while waiting for the command finish:

import paramiko
import time
import yappi

private_key_file = "/path/to/key"
proxy_command = "ssh -l user -i /home/user/.ssh/id_rsa -W 1.2.3.4:22 -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null 5.6.7.8"

sock = paramiko.proxy.ProxyCommand(proxy_command)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
ssh.connect("1.2.3.4", username="root", key_filename=private_key_file, sock=sock)

yappi.start()
stdin, stdout, stderr = ssh.exec_command('sleep 30')
while not stdout.channel.exit_status_ready():
    time.sleep(1)
yappi.get_func_stats().print_all()

Script output:

$ python bug.py

Clock type: CPU
Ordered by: totaltime, desc

name                                  ncall  tsub      ttot      tavg      
..miko/proxy.py:70 ProxyCommand.recv  315..  11.48050  30.41141  0.096544
..ket.py:323 Packetizer.read_message  6/5    0.000218  30.03361  5.005602
../packet.py:185 Packetizer.read_all  12/11  0.000000  30.03326  2.502771
..ient.py:288 SSHClient.exec_command  1      0.000083  0.018942  0.018942
..port.py:530 Transport.open_session  1      0.000014  0.017733  0.017733
..port.py:583 Transport.open_channel  1      0.000163  0.017719  0.017719
..on2.7/threading.py:400 _Event.wait  9      0.000078  0.016533  0.001837
..7/threading.py:235 _Condition.wait  5      0.000473  0.016397  0.003279
..:1291 Transport._send_user_message  4      0.000073  0.001438  0.000360
..rt.py:1288 Transport._send_message  4      0.000024  0.001287  0.000322
..ket.py:279 Packetizer.send_message  4      0.000157  0.001263  0.000316
[...]
@jasondunsmore jasondunsmore changed the title from Paramiko uses 100% CPU in ProxyCommand.recv() to Paramiko uses 100% CPU with ProxyCommand Oct 2, 2014
@jasondunsmore

Submitted a pull request to fix this #414

@bitprophet
Member

Closing in favor of the PR, thanks!

@bitprophet bitprophet closed this Oct 7, 2014
@bitprophet bitprophet added a commit that referenced this issue Dec 17, 2014
@bitprophet bitprophet Changelog closes #413 c0520ad
@bitprophet bitprophet added a commit that referenced this issue Dec 18, 2014
@bitprophet bitprophet Changelog re #413, closes #454 741b4fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment