File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -283,19 +283,35 @@ require()
283283
284284csync2_u ()
285285{
286+ local tmp kid now client_exit nc_exit server_exit
286287if csync2 -N $1 -M > /dev/null; then
287288csync2 -N $2 -iii -vvv &
288289kid=$!
289290
291+ # try to avoid the connect-before-listen race,
292+ # wait for the expected listening socket to show up,
293+ # with timeout using bash magic $SECONDS.
294+ now=$SECONDS
295+ while ! ss -tnl src $2 :csync2 | grep -q ^LISTEN; do
296+ kill -0 $kid
297+ (( SECONDS - now < 2 ))
298+ sleep 0.1
299+ done
300+
290301csync2 -N $1 -uvvv
291302client_exit=$?
292303
293- # server still alive?
294- # then no connection was made...
295- # attempt do one now.
296- tmp=$( nc $2 $CSYNC2_PORT <<< " BYE" )
297- nc_exit=$?
298-
304+ if ss -tnl src $2 :csync2 | grep -q ^LISTEN; then
305+ # server still alive?
306+ # then no connection was made...
307+ # attempt to do one now.
308+ tmp=$( nc $2 $CSYNC2_PORT <<< " BYE" )
309+ nc_exit=$?
310+
311+ [[ $nc_exit = 0 ]] || kill $kid
312+ else
313+ nc_exit=1
314+ fi
299315wait $kid
300316server_exit=$?
301317[[ $client_exit = 0 && $server_exit = 0 && $nc_exit != 0 ]]
You can’t perform that action at this time.
0 commit comments