Skip to content

Bug: wait with no timeout with XNU times out after 72 minutes #1475

@aittalam

Description

@aittalam

Contact Details

davide.eynard@gmail.com, davide@mozilla.ai

What happened?

While testing llamafile cosmocc builds, I realised the idle server was timing out after ~72 minutes.
I tested it both in older (0.6.2) versions, more recent (0.9.3) and mine (0.10.0) and saw the problem occurred only in the last two.

I wrapped up a report with Claude documenting my investigation. I provide that as reference but I realise it's quite verbose, so here's a short summary that is relevant to cosmopolitan: when cosmo_futex_wait is called with no timeout (as happens with e.g. pthread_cond_wait), the XNU code path sets the timeout to UINT32_MAX microseconds instead of 0 (see here). This results in not waiting for infinity, but for UINT32_MAX microseconds (which is ~72 minutes).

Version

4.0.2

What operating system are you seeing the problem on?

Mac

Relevant log output

$ (start=$SECONDS; while true; do elapsed=$((SECONDS - start)); printf "\r⏱ %d min %d sec elapsed" $((elapsed/60)) $((elapsed%60)); sleep 60; done) & timer_pid=$!
$ llamafile --model gemma-3-27b-it-Q5_K_M.gguf --server --verbose

...

⏱ 71 min 1 sec elapsedlibc++abi: terminating due to uncaught exception of type std::__1::system_error: condition_variable wait failed: Connection timed out

Metadata

Metadata

Assignees

No one assigned

    Labels

    medium severityUsed to report medium severity bugs (e.g. Malfunctioning Features but still useable)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions