Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paramiko uses 100% CPU with ProxyCommand #413

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

Paramiko uses 100% CPU with ProxyCommand #413

jasondunsmore opened this issue Oct 2, 2014 · 2 comments

Comments

@jasondunsmore
Copy link

@jasondunsmore jasondunsmore commented Oct 2, 2014

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 Paramiko uses 100% CPU in ProxyCommand.recv() Paramiko uses 100% CPU with ProxyCommand Oct 2, 2014
@jasondunsmore
Copy link
Author

@jasondunsmore jasondunsmore commented Oct 3, 2014

Submitted a pull request to fix this #414

@bitprophet
Copy link
Member

@bitprophet bitprophet commented Oct 7, 2014

Closing in favor of the PR, thanks!

@bitprophet bitprophet closed this Oct 7, 2014
bitprophet added a commit that referenced this issue Dec 17, 2014
bitprophet added a commit that referenced this issue Dec 17, 2014
bitprophet added a commit that referenced this issue Dec 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants