Skip to content

Commit 11c42cb

Browse files
committed
startDaemon(): Detect if the daemon crashes before creating the socket
This avoids timeouts like those seen in https://github.com/NixOS/nix/actions/runs/13376958708/job/37358120348?pr=6962.
1 parent 9427c02 commit 11c42cb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/functional/common/functions.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ startDaemon() {
6767
die "startDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
6868
fi
6969

70-
# Dont start the daemon twice, as this would just make it loop indefinitely
70+
# Don't start the daemon twice, as this would just make it loop indefinitely.
7171
if [[ "${_NIX_TEST_DAEMON_PID-}" != '' ]]; then
7272
return
7373
fi
@@ -76,15 +76,19 @@ startDaemon() {
7676
PATH=$DAEMON_PATH nix --extra-experimental-features 'nix-command' daemon &
7777
_NIX_TEST_DAEMON_PID=$!
7878
export _NIX_TEST_DAEMON_PID
79-
for ((i = 0; i < 300; i++)); do
79+
for ((i = 0; i < 60; i++)); do
8080
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then
8181
DAEMON_STARTED=1
8282
break;
8383
fi
84+
if ! kill -0 "$_NIX_TEST_DAEMON_PID"; then
85+
echo "daemon died unexpectedly" >&2
86+
exit 1
87+
fi
8488
sleep 0.1
8589
done
8690
if [[ -z ${DAEMON_STARTED+x} ]]; then
87-
fail "Didnt manage to start the daemon"
91+
fail "Didn't manage to start the daemon"
8892
fi
8993
trap "killDaemon" EXIT
9094
# Save for if daemon is killed
@@ -97,7 +101,7 @@ killDaemon() {
97101
die "killDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
98102
fi
99103

100-
# Dont fail trying to stop a non-existant daemon twice
104+
# Don't fail trying to stop a non-existant daemon twice.
101105
if [[ "${_NIX_TEST_DAEMON_PID-}" == '' ]]; then
102106
return
103107
fi
@@ -219,7 +223,7 @@ assertStderr() {
219223

220224
needLocalStore() {
221225
if [[ "$NIX_REMOTE" == "daemon" ]]; then
222-
skipTest "Cant run through the daemon ($1)"
226+
skipTest "Can't run through the daemon ($1)"
223227
fi
224228
}
225229

0 commit comments

Comments
 (0)