Skip to content

Commit 4cb05fa

Browse files
committed
fix(daemon): retry the cohort claim across a generation handoff
With the Windows client-connection cluster fixed, the smoke's rapid session churn exposed the next layer: each phase starts a fresh first-session daemon, and a just-superseded generation still holds the cohort daemon-claim EX lock for the brief window between going client-terminal (which lets the next generation start) and releasing its cohort locks. claim_acquire was a single non-blocking attempt, so the new daemon failed immediately with daemon.start_failed component=claim and the client saw "daemon could not start within 30000 ms". The host now retries the claim on BUSY for a bounded 12 s handoff window (well under the client's 30 s budget); a persistent BUSY still fails as a real conflict. Cross-platform path, POSIX-syntax verified. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 53d867d commit 4cb05fa

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎src/daemon/host.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ enum {
3737
HOST_APPLICATION_SHUTDOWN_MS = 10000,
3838
HOST_COORDINATION_CLEANUP_MS = 500,
3939
HOST_INITIAL_CLIENT_TIMEOUT_MS = 10000,
40+
/* A just-superseded daemon generation can still hold the cohort claim for
41+
* the brief window between going client-terminal (which lets the next
42+
* generation start) and releasing its cohort locks. Wait out that handoff
43+
* rather than failing startup on a transient BUSY. Bounded well under the
44+
* client's 30 s daemon-start budget. */
45+
HOST_DAEMON_CLAIM_TIMEOUT_MS = 12000,
4046
HOST_WAIT_TICK_MS = 100,
4147
HOST_HTTP_CONFIG_POLL_MS = 1000,
4248
HOST_HTTP_RETRY_INITIAL_MS = 1000,
@@ -799,8 +805,16 @@ int cbm_daemon_host_run(const cbm_daemon_host_config_t *config) {
799805
return -1;
800806
}
801807
cbm_version_cohort_daemon_claim_t *daemon_claim = NULL;
802-
if (cbm_version_cohort_daemon_claim_acquire(cohort_manager, &daemon_claim) !=
803-
CBM_VERSION_COHORT_OK) {
808+
uint64_t claim_deadline = host_deadline_after(HOST_DAEMON_CLAIM_TIMEOUT_MS);
809+
cbm_version_cohort_status_t claim_status =
810+
cbm_version_cohort_daemon_claim_acquire(cohort_manager, &daemon_claim);
811+
while (claim_status == CBM_VERSION_COHORT_BUSY && cbm_now_ms() < claim_deadline) {
812+
/* The previous generation is releasing; retry until the claim is free
813+
* or the handoff window elapses (a persistent BUSY = a real conflict). */
814+
cbm_usleep(HOST_WAIT_TICK_MS * 1000);
815+
claim_status = cbm_version_cohort_daemon_claim_acquire(cohort_manager, &daemon_claim);
816+
}
817+
if (claim_status != CBM_VERSION_COHORT_OK) {
804818
cbm_log_error("daemon.start_failed", "component", "claim");
805819
host_participant_guard_close(&participant_guard);
806820
host_daemon_claim_close(&daemon_claim);

0 commit comments

Comments
 (0)