-
Notifications
You must be signed in to change notification settings - Fork 151
ParallelSSHClient: timeout option with proxy host #76
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
Comments
@fsaintma and dear Maintainer I tried to reproduce a host that could have this behavior. This can be achieved by setting an iptable that drops tcp packets on a port: http://unix.stackexchange.com/a/330537 You can try with our 'grenoble.iot-lab.info' server on port 22222 for example. (Or any port that is not open, == not 22 and not 2222) With proxy trough localhost
Without proxy
I did not run ParallelSSH code, I just tried to reproduce the output with openssh-client to make it easily testable. |
Hi, thanks for raising. Yes, looks like timeout parameter is not passed onto the proxy client. Simple fix fortunately. Will also update the docstring regarding default timeout setting. For the other comment, Eg:
Output: There is also a 5 second delay between connection attempts, so for retries=2 with timeout=5 total time before timeout would be 15sec. This was not made clear in documentation though so will update accordingly. |
Hmm, forget what I said, looks like timeout is in fact passed to proxy and works as expected. With unreachable proxy and timeout set:
Output:
Without unreachable proxy the above completes without errors. So the additional delay you are seeing is coming from the retry attempts, not proxy timeout not being set. Documentation update for the retry behaviour has been made. |
Thanks @cladmi, there is a test for proxy failures already :) |
Hi @pkittenis and @cladmi I'm sorry but if I use your script with my unreachable host node-a8-111.grenoble.iot-lab.info I obtain the same result. Indeed in my case the proxy host is reachable but not the host behind the proxy host (eg. blocked TCP connection)
Output
So it's not a proxy failure but a host failure behind a proxy. Thanks in advance. |
Ah, right so the behaviour is when proxy is reachable but remote host is not. In that case, the timeout setting for proxy -> host connection is not configurable on our client side as that is a proxy server side connection made by the SSH server on proxy host. Client side retries are not applicable either, proxy host may be doing that also. ParallelSSH, and any client for that matter, can only affect its own connections - the proxy initiated connection is not one of them. That timeout configuration can only be changed on the proxy host itself. Eg:
Proxy host is Changing localhost SSH settings to lower timeout changes this:
In short, will need to set an appropriate ssh config on the proxy server for the desired timeout. |
Thank you for your quick answers. From what I understand, I don't think its a configuration that should be done on the server. For me what happens in practice is
Tell me if I'm wrong, or if it is different with So, I would think that the timeout configuration should be on this intermediate tunnel. So maybe when creating the proxy_channel here: https://github.com/ParallelSSH/parallel-ssh/blob/master/pssh/ssh_client.py#L147 I may be missing what the intermediate connection is really made of in I will try tweaking this. If there is no way to control this using tcp configuration, it would also be possible, but more complex and heavier, to have a local timer/thread/greenlet/process/signal/…, that closes the whole connection if it is not established after |
Indeed, adding "timeout=self.timeout" to open_channel does raise an exception in SSHClient: You need a "recent" enough version of paramiko that supports this option.
However it is not currently handled in ParallelSSHClient:
With this however, the connection time could be |
If you want we can do a PR with propositions to fix this. Like if you want more (timeout - elapsed_time), or a new argument like proxy_timeout, or just ignore it as it's already the case when creating the proxy connection. |
That's not quite what happens but yes, looks like there is now a timeout setting on the channel which can be set by client. It's a relatively small change, will need a bump in minimum paramiko version though. What happens in practice on SSH protocol tunnel connections is
This is the 'direct-tcpip tunneling' feature of the SSH(v2) protocol In the case of using the tunnel as a proxy to another SSH host, the tunnel connection is then used by client to initiate a new SSH channel to the remote host via the intermediate proxy. ProxyCommand is an openssh client feature to use an external program to proxy through, not related here as ParallelSSHClient uses the SSH protocol's native tunneling feature instead. The tunnel connection is initiated and managed by the SSH server. See for example connections created by:
Client -> proxy server
Proxy server -> remote host
As can be seen above, the remote host connection is coming from the SSH server's IP rather than client. It is timing out waiting for a syn/ack reply from remote host which does not exist, as expected. Changing timeout settings on the SSH server does affect this connection's timeout. However, it is now possible for timeout to be passed on to server when initiating the tunnel connection which is easier and good to have. Eg with
This will need some additional error handling though as previously any errors would happen when initiating the SSH connection via the tunnel, not when creating tunnel itself. That breaks output, note it is empty above. Thanks for the info @cladmi, was not aware of that new setting :) If you'd like to make changes needed would be happy to review, otherwise can wait for next release - it's not a big change so no problem either way. What is needed is I think:
The first three are in tunnel_timeout branch already, can use that to test if it resolves your issue and/or branch off of. Existing timeout setting is fine, don't need new one. By handling tunnel timeout on tunnel channel creation the code doesn't try to create a new ssh connection with its own timeout so no 2x timeouts. |
@pkittenis and @cladmi Congratulations !!!!! I have just tested the tunnel_timeout branch and it's OK for me, it resolves my issue. Script output (timeout=15)Connecting via SSH proxy grenoble.iot-lab.info:22 -> node-a8-111.grenoble.iot-lab.info:22 Thanks very much. |
Thank you |
Thank you also for the info :) |
Thanks very much @pkittenis for your work and reactivity !!! |
Hi @pkittenis It's ok for Pypi and long life to parallel-ssh !!! |
No worries, thanks for letting me know. The pypi release from travis failed for some reason. |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I have just tried to test with a Python script ParallelSSHClient and run_command with approximately 50 hosts behind a proxy host.
I've realized that if you had one host in your host list which didn't boot correctly but you still establish a blocking TCP connexion the run_command return the output after bit more two minutes (eg. raise exception Connect Failed). So I decided to pass timeout option to the client with 10 seconds but the behaviour is the same and I must wait two minutes. So I pushed my script on the proxy host and launch ParallelSSHClient without proxy_host option and the output is returned after 10 seconds with an exception as expected (eg. timed out) .
Can you confirm me this behaviour and how I should apply a timeout for my hosts list SSH connection when I specify a proxy_host ? Indeed I don't want to wait two minutes in the case of all hosts boot correctly except one.
You can see below my script and the result of the tests with one host.
Thanks in advance for your help
NOTE1 : If I want a timeout of 10 seconds I must specify .10 (with 10 I must wait 40 seconds).
NOTE2 : I notice in your documentation that you have a timeout=120 in ParallelSSHClient method and a typo in docstring with "Defaults to 10".
script
with_proxy : script launch on my computer
without_proxy: script launch on the proxy host
The text was updated successfully, but these errors were encountered: