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

Add a timeout on connecting to a TCP device #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dennisschroer
Copy link

In our setup (running inside docker), opening a connection to a TCP device has a long timeout (128 seconds). That means that the script will start by trying to connect to the device. If this is not immediately succesful, it takes 128 for the command to fail. So if the device is actualy available after 10 seconds, we wait 118 seconds too much.

This setting is defined in the source, and is is not possible to change this timeout in bash. A workaround is to add a timeout to the command attempting a connection to the device.

This solution is based on https://stackoverflow.com/a/40158514

@vpriscan
Copy link

vpriscan commented Dec 8, 2020

Also, script can be changed to prefer using nc command, or even netcat or ncat if any of those commands exist, and not just when BusyBox is used (this is how the script is currently implemented).

Furthermore, -w flag (which stands for timeout) set to the value of e.g. 1 second needs to be added to nc command in the script, as traditional netcat implementation has no default timeout, and newer Ncat implementation has a default timeout of 10 seconds, meaning that without the -w flag, the wait-for-it.sh script would behave very differently depending on which nc is installed.

@atkrad
Copy link

atkrad commented Jun 15, 2022

Hey @dennisschroer

You can use the Wait4X, It's already supported TCP connection timeout.

Example:
wait4x tcp 127.0.0.1:80 --connection-timeout=10s --timeout=500s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants