Skip to content

Commit 5c69c14

Browse files
authored
Merge pull request DeusData#2272 from DeusData/fix/test-daemon-bootstrap-sync-spawn
fix(test): the ENOSPC bootstrap test no longer lets a deadline decide its verdict
2 parents 5958f54 + 9b5bf70 commit 5c69c14

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

‎tests/test_daemon_bootstrap.c‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ typedef struct {
893893
char parent[BOOTSTRAP_TEST_PATH_CAP];
894894
cbm_daemon_build_identity_t identity;
895895
pid_t children[BOOTSTRAP_ENOSPC_MAX_CHILDREN];
896+
int exit_status[BOOTSTRAP_ENOSPC_MAX_CHILDREN];
897+
bool reaped[BOOTSTRAP_ENOSPC_MAX_CHILDREN];
896898
size_t child_count;
897899
size_t spawn_calls;
898900
} bootstrap_enospc_host_t;
@@ -928,19 +930,40 @@ static bool bootstrap_enospc_host_spawn(void *opaque,
928930
int run_result = endpoint ? cbm_daemon_host_run(&config) : 0;
929931
_exit(run_result == -1 ? 0 : 50);
930932
}
931-
state->children[state->child_count++] = child;
933+
/* SYNCHRONOUS on purpose. The daemon host writes its start-failure record
934+
* and only then lets go of its lifetime reservation and exits, so once it
935+
* has been reaped "record on disk, reservation released" is a STABLE state
936+
* pinned by construction. The client's first look after the spawn (the
937+
* wait loop always runs once and its first failure check is unthrottled)
938+
* therefore finds the record however long the host took to get there.
939+
*
940+
* Returning while the host was still running made the verdict ride on the
941+
* client's 30 s startup deadline: before it listens the host SHA-256s its
942+
* own image, which for the ~450 MB test runner is ~3 s natively and ~26 s
943+
* under MSan (48 CI samples: 20-32 s). The deadline won that race on slow
944+
* runs and the reaper then SIGKILLed a host that had not failed yet --
945+
* `ASSERT(daemon_named_cause)` red on PRs that touch no C at all (#2245,
946+
* #2158, #2140). A deadline must never decide a test (O9). */
947+
size_t slot = state->child_count++;
948+
state->children[slot] = child;
949+
int status = 0;
950+
pid_t waited;
951+
do {
952+
waited = waitpid(child, &status, 0);
953+
} while (waited < 0 && errno == EINTR);
954+
state->reaped[slot] = waited == child;
955+
state->exit_status[slot] = status;
932956
return true;
933957
}
934958

935959
static void bootstrap_enospc_reap(bootstrap_enospc_host_t *state, int *nonzero_exits) {
936960
*nonzero_exits = 0;
937961
for (size_t i = 0; i < state->child_count; i++) {
938-
int status = 0;
939-
pid_t waited;
940-
do {
941-
waited = waitpid(state->children[i], &status, WNOHANG);
942-
} while (waited < 0 && errno == EINTR);
943-
if (waited == 0) {
962+
int status = state->exit_status[i];
963+
if (!state->reaped[i]) {
964+
/* Only reachable when the synchronous wait in the spawn itself
965+
* failed; never leave a host behind. */
966+
pid_t waited;
944967
(void)kill(state->children[i], SIGKILL);
945968
do {
946969
waited = waitpid(state->children[i], &status, 0);

0 commit comments

Comments
 (0)