-
Notifications
You must be signed in to change notification settings - Fork 185
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
Make SSH_TIMEOUT an overridable argument #156
base: master
Are you sure you want to change the base?
Conversation
This change is not backward compatible. It looks nice, but what the reason? |
Hi @pahaz - sorry for the delay in response. The reason is that the default timeout period is too long to detect an inactive gateway. In my project, if a session is initiated to a device that is unreachable or otherwise inaccessible, the default 120s timeout must expire prior to any further action taking place which is a problem in my case. Can you provide more detail on how this change is not backwards compatible? It seems to me that the codebase relies on calling Thanks! |
@checktheroads It seems to me that if you made the default None, then that would be backwards compatible with the current behavior. (i.e. if someone has a server which takes 31 seconds to respond, their code will keep working when they upgrade to the new version.) This does mean that people would only benefit from having a timeout if they explicitly set one. In general, I do think it is a good idea to have timeouts by default, but I think it's also reasonable to insist on backwards compatibility. |
@nickodell thank you - wasn't following at first, but your mention of @pahaz - will this suffice? PS: something appears to be wrong with CircleCI, I see the tests are failing on this commit due to |
It does pass tests in Python 3.4, though. 🎉 It looks like the test error is related to this issue: TheKevJames/coveralls-python#213 sshtunnel depends on tox, which depends on the coverage library. Coveralls also depends on coverage library, so the first time you install dependencies, you install a version which is incompatible with coveralls. We should try one of the recommendations in that thread:
|
@@ -46,8 +46,6 @@ | |||
TRACE_LEVEL = 1 | |||
_CONNECTION_COUNTER = 1 | |||
_LOCK = threading.Lock() | |||
#: Timeout (seconds) for the connection to the SSH gateway, ``None`` to disable | |||
SSH_TIMEOUT = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that someone uses code like so:
import sshtunnel
import threading
import time
# incompatible !
sshtunnel.SSH_TIMEOUT = 3
tunnel = sshtunnel.SSHTunnelForwarder(
('172.18.19.20', 22),
ssh_username='user',
ssh_password='password',
remote_bind_address=('192.168.1.10', 24),
set_keepalive=0.5
)
It's already a part of a public API :(
You can just use it as default for gateway_timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't considered that. Okay, that's fixable.
What do you think about the following?
- Leave SSH_TIMEOUT where it is.
#: Timeout (seconds) for the connection to the SSH gateway, ``None`` to disable
SSH_TIMEOUT = None
- In the constructor for SSHTunnelForwarder, set self.gateway_timeout based upon both the argument and the global value:
self.gateway_timeout = gateway_timeout if gateway_timeout is not None else SSH_TIMEOUT
In the public API, there would be two ways to set the timeouts. One would be global, and the other would be for a single instance. If you set both timeouts, the setting on the specific instance is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's ok
Please update from master. It looks like a conflict with https://github.com/pahaz/sshtunnel/pull/195/files |
Just my additional 2 cents: I encountered an issue with my project where the gateway was stuck on trying to connect to a downed host for a couple of days and had to be terminated manually, where introducing the exact change this PR is suggesting (and overriding the timeout to something sensible) solved it. |
Same problem in my project. Using sshtunnel==0.4.0, SSH_TIMEOUT does not seem to be configurable |
Hello,
I'm working to integrate this awesome project into a project of mine, but kept running into an issue when testing connectivity to an SSH proxy server that was unreachable. In my tests, the tunnel connection took a full 120 seconds to time out and raise an exception. When I modified the original constant
SSH_TIMEOUT
to, say, 10, the session timed out after 10 seconds as was useful for my purposes.In this PR I set a generous default timeout period of 30 seconds, but this could be adjusted if needed.
Thanks!