Skip to content

Commit fa14690

Browse files
committed
Make nc time out in a known amount of time instead of hanging
1 parent 4a309cc commit fa14690

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

wait-for

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ USAGE
3232

3333
wait_for() {
3434
for i in `seq $TIMEOUT` ; do
35-
nc -z "$HOST" "$PORT" > /dev/null 2>&1
35+
# use a 1-second timeout, but still sleep 0.1 seconds after just to be safe
36+
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
3637

3738
result=$?
3839
if [ $result -eq 0 ] ; then
@@ -41,7 +42,7 @@ wait_for() {
4142
fi
4243
exit 0
4344
fi
44-
sleep 1
45+
sleep 0.1
4546
done
4647
echo "Operation timed out" >&2
4748
if [ $result -ne 0 ] && [ $STRICT -ne 1 ] ; then

0 commit comments

Comments
 (0)