Skip to content

cbm_nanosleep never resumes after EINTR: every timed wait can be silently truncated #1616

Description

@moffermann

What

On POSIX cbm_nanosleep is raw nanosleep (src/foundation/compat.h:96), and all four call sites
pass rem = NULL and discard the return value:

  • src/foundation/subprocess.c:958cbm_spawn_backoff, the spawn-retry patience
  • src/daemon/bootstrap.c:274
  • src/daemon/runtime.c:275
  • src/foundation/diagnostics.c:464

nanosleep returns EINTR on any signal delivered to the calling thread, and unlike most blocking
calls it is not restarted by SA_RESTART — the remaining time is simply lost unless the caller
loops on rem. So every one of these waits can end early by an arbitrary amount, silently.

Why it matters

cbm_spawn_backoff is the clearest case. The comments around
CBM_SPAWN_RETRY_ATTEMPTS promise ~630 ms of patience on an ordinary build and ~5 s on a sanitized
one, and that is the whole point of the retry: ride out a burst of process creation instead of
failing a spawn that would have succeeded. A signal arriving mid-backoff cuts that budget to a
fraction of what the code says it is, and nothing reports it.

src/cli/hook_augment.c:133 installs a SIGALRM handler, so this is reachable and not theoretical.

Why this is an issue and not a PR

Suggested shape

Add cbm_nanosleep_full() (loop while nanosleep returns -1/EINTR, feeding rem back in;
Windows Sleep already has no interruptible failure mode) and move the call sites that want an
uninterruptible wait — starting with cbm_spawn_backoff — over to it. Leave the daemon pauses on
the interruptible primitive if that is the intent, with a comment saying so.

Found while reviewing the sanitized-build wiring in #1615; unrelated to that change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority/normalStandard review queue; useful PR with ordinary maintainer urgency.stability/performanceServer crashes, OOM, hangs, high CPU/memory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions