question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout for Device.open()

See original GitHub issue

I have been going through the code and scratching my head as to how to get Device to timeout in a reasonable amount of time when I first call open(). The specific scenario is to have netconf enabled on the device via ssh but the protect RE firewall filter does not allow netconf access. On such a device it takes upwards or 2 minutes to timeout the connection on open() which gets extremely annoying when I am trying to connect to many devices.

I would like to have the ability to pass a timeout value to open() to quickly throw an error on a connection that will never open in the first place.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
attila123commented, Sep 4, 2019

TL;DR: it should be possible to set ssh connect timeout via the “connecttimeout” parameter in ~/.ssh/config (or some other ssh config file with custom path). I did some debugging and looks like:

connecttimeout=42

and re-run my debugging. The value 42 was read and applied in https://github.com/ncclient/ncclient/blob/v0.6.6/ncclient/transport/ssh.py#L403 BTW the ssh_config man page (see on your computer or e.g. at https://linux.die.net/man/5/ssh_config) says that the keywords are case-insensitive and indeed it is parsed like that (ncclient uses the config parsing of paramiko (ssh client library) which converts the keywords to lowercase).

Update: to test this I created a “black hole” IP address such that all packets sent to it from my computer will be dropped:

sudo iptables -A OUTPUT -d 10.22.215.174 -j DROP

I verified that the command line ssh client now times out in 42s using this IP:

$  time ssh 10.22.215.174
ssh: connect to host 10.22.215.174 port 22: Connection timed out
ssh 10.22.215.174  0,01s user 0,00s system 0% cpu 42,056 total

So far so good. I also verified that socket connect at https://github.com/ncclient/ncclient/blob/v0.6.6/ncclient/transport/ssh.py#L409 timed out in 42s and there was some timeout exception raised. When not using the “connecttimeout” in ~/.ssh/config then I got the jnpr.junos.exception.ConnectTimeoutError in about 96-99 sec (but in your system it might be different).

Update2: at one occasion I saw the timeout happening in about 11 sec (if I am not mistaken). (then again 42 without any code change) Could be a python (3.7.4) or Linux kernel (5.1.21) issue??? But usually it works correctly, so maybe it was an exceptional case.

1reaction
njayaramacommented, May 30, 2018

what is current timeout value of the open()? is there any plan to fix this issue, am hitting this one on my network. I need to increase the timeout value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Junos PyEZ Errors When Configuring Junos ...
Problem. Description. The Junos PyEZ code generates an RpcTimeoutError message or a TimeoutExpiredError message and fails to update the device configuration.
Read more >
What Does a Server Connection Timeout Mean?
A server connection timeout means that a server is taking too long to reply to a data request made from another device. Timeouts...
Read more >
open() timeout - Phidgets.com
Re: open() timeout ... That make sense. I've landed on calling openWaitForAttachment() initially then in the exception handler when it timesout ...
Read more >
The device, \Device\Ide\iaStor0, did not respond ... - TechNet
... \Device\Ide\iaStor0, did not respond within the timeout period. ... Left click "Port0" to open and in the pane with Name/Type/Data, ...
Read more >
6.10. timeout
A following read() can take as long as the user likes. Timeouts are best avoided, especially if SCSI bus resets will adversely effect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found