Skip to content

pssh.clients (version 1.6.1 and above) does not timeout on bad IPs. But pssh.pssh_client works.. #133

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

Closed
gopalagrawal opened this issue Aug 31, 2018 · 1 comment
Labels

Comments

@gopalagrawal
Copy link

Bug reports

pssh.clients does not timeout if an invalid (non-reachable) IP is given, but pssh.pssh_client (deprecated method) timesout as expected. I suspect some bug has been introduced in the recent method.

Steps to reproduce:

CODE:

from pssh.clients import ParallelSSHClient
from pssh.exceptions import Timeout

   hosts = [ IP1, IP2 ...  ]   #Have at least one bad IP in here. 
   host_config = { IP1: { 'user':'root',  'password': 'mypass', 'port':22 },  IP2: ...  }

    clients = ParallelSSHClient(hosts, host_config=host_config, num_retries=1, timeout=5)
    output = clients.run_command("echo Hello", stop_on_errors=False)  <-- Hangs here forever. 
    try:   <-- Never reaches this point. 
        clients.join(output)
    except Timeout:
        pass

STACK TRACE WHEN PRESSING ^C
Run the file with #python test.py
<It hangs forever and need to press ^C to get out".

  File "/root/project/.fenv/local/lib/python2.7/site-packages/pssh/clients/native/parallel.py", line 188, in run_command
    encoding=encoding, use_pty=use_pty, timeout=timeout)
  File "/root/project/.fenv/local/lib/python2.7/site-packages/pssh/clients/base_pssh.py", line 91, in run_command
    self.get_output(cmd, output)
  File "//root/project/.fenv/local/lib/python2.7/site-packages/pssh/clients/base_pssh.py", line 145, in get_output
    (channel, host, stdout, stderr, stdin) = cmd.get()
  File "src/gevent/greenlet.py", line 654, in gevent._greenlet.Greenlet.get
  File "src/gevent/greenlet.py", line 642, in gevent._greenlet.Greenlet.get
  File "src/gevent/_greenlet_primitives.py", line 59, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 63, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/__greenlet_primitives.pxd", line 35, in gevent.__greenlet_primitives._greenlet_switch
KeyboardInterrupt

Expected behaviour: [What was expected to happen.]
It should have timed out and given the result for the rest of the IP's which were valid.

Actual behaviour: [What actually happened.]
It hangs forever. However, if you replace the import pssh.clients with the deprecated method pssh.pssh_client, it will timeout as expected for the bad IPs.

Additional info: [Include version of ssh2-python and/or paramiko and any other relevant information.]
Some of the relevant libs in my virtualenv.

configparser==3.5.0
cryptography==1.9
eventlet==0.21.0
gevent==1.3.1
greenlet==0.4.13
ipaddress==1.0.18
parallel-ssh==1.6.1
paramiko==2.1.2
passlib==1.7.1
pycrypto==2.6.1
pyOpenSSL==17.0.0
pycrypto==2.6.1
pyOpenSSL==17.0.0
ssh2-python==0.13.0.post2

@pkittenis pkittenis added the bug label Aug 31, 2018
@pkittenis
Copy link
Member

pkittenis commented Aug 31, 2018

Hi there,

Thanks for the interest and reproducible report.

Looks like a bug in the way timeout setting is applied to socket used by native client. The back-end library expects timeout in ms, while gevent socket timeout is in seconds. The timeout is wrongly applied to the socket, making it longer than the intended setting.

pkittenis pushed a commit that referenced this issue Sep 1, 2018
Added native clients integration tests for client timeout connecting to unreachable or unknown host.
Resolves #133
pkittenis pushed a commit that referenced this issue Sep 1, 2018
Added native clients integration tests for client timeout connecting to unreachable or unknown host.
Resolves #133
pkittenis pushed a commit that referenced this issue Sep 4, 2018
Added native clients integration tests for client timeout connecting to unreachable or unknown host.
Resolves #133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants