Skip to content

Commit 5a7a56e

Browse files
committed
when on OSX, use all relevant nc timeout options
1 parent d101d61 commit 5a7a56e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

wait-for

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,20 @@ USAGE
3030
exit "$exitcode"
3131
}
3232

33+
test_connection() {
34+
# force a 1-second timeout on darwin (https://stackoverflow.com/a/20460402/2063546)
35+
if [ -z "${OSTYPE##*darwin*}" ] ; then
36+
nc -z -w 1 -G 1 "$1" "$2" > /dev/null 2>&1
37+
else
38+
nc -z -w 1 "$1" "$2" > /dev/null 2>&1
39+
fi
40+
}
41+
3342
wait_for() {
3443
for i in `seq $TIMEOUT` ; do
35-
# use a 1-second timeout
36-
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
37-
44+
# use a 1-second timeout, but still sleep 0.1 seconds after just to be safe
45+
test_connection "$HOST" "$PORT"
46+
3847
result=$?
3948
if [ $result -eq 0 ] ; then
4049
if [ $# -gt 0 ] ; then

0 commit comments

Comments
 (0)