Skip to content

bug: Uvicorn workers still dying with --timeout-worker-healthcheck 120 #131

Closed

Description

@vybe

Summary

Uvicorn workers continue to die intermittently despite upgrading to uvicorn 0.37.0 and setting --timeout-worker-healthcheck 120. Workers are SIGKILL'd every few hours with no traceback or OOM indication, causing in-flight async tasks (scheduled execution launches) to be silently dropped. This results in executions stuck in "running" state with no Claude session ever created.

Component

Backend / Uvicorn Worker Management

Priority

P2

Error

INFO:     Waiting for child process [PID]
INFO:     Child process [PID] died
(trapped) error reading bcrypt version

No traceback, no OOM, no application-level error logged before the death.

Observed Behavior

With --workers 2 --timeout-worker-healthcheck 120, worker deaths observed at irregular intervals:

Worker Died After Notes
Worker A ~4.5h
Worker B ~1h
Worker C ~7h
Worker D ~19.5h Was handling scheduled execution launch
Worker E ~16h Was handling scheduled execution launch
  • No container memory limit set
  • Container using 1GB / 31GB RAM (3%)
  • No kernel OOM killer entries in dmesg
  • Workers die silently — only the parent process logs the death

Impact

When a worker dies while handling an async execution launch:

  1. The execution record is created in the DB with status "running"
  2. A Redis capacity slot is acquired
  3. The background task that runs docker exec to start Claude is lost
  4. The execution is stuck forever — no session, no completion, slot held

The scheduler then polls for up to 1 hour before giving up with "Polling deadline exceeded".

Location

  • File: Uvicorn process management (external dependency)
  • Config: --workers 2 --timeout-worker-healthcheck 120 in backend container CMD

Root Cause

The --timeout-worker-healthcheck 120 raised the threshold but didn't eliminate the problem. Something is still blocking the Python GIL for >120 seconds occasionally, causing the uvicorn parent to SIGKILL the unresponsive worker. Possible causes:

  1. Long-running synchronous docker exec calls via the Docker SDK blocking the GIL
  2. SQLite write locks causing contention between the 2 workers
  3. passlib/bcrypt operations (the (trapped) error reading bcrypt version on restart hints at bcrypt issues)
  4. Synchronous HTTP calls to agent containers during execution launch

Reproduction Steps

  1. Deploy backend with --workers 2 --timeout-worker-healthcheck 120
  2. Run multiple agents with hourly scheduled tasks
  3. Monitor worker deaths: docker logs trinity-backend 2>&1 | grep "Child process.*died"
  4. Correlate with stuck executions: query schedule_executions where status='running' AND claude_session_id IS NULL

Suggested Fix

Options (in order of preference):

Option A: Switch to --workers 1
Eliminates GIL contention between workers entirely. Since async operations (FastAPI) handle concurrency via the event loop, a single worker may be sufficient. This also eliminates SQLite multi-writer issues.

Option B: Increase timeout further

--timeout-worker-healthcheck 300

May just delay the problem rather than fix it.

Option C: Make execution launch fully async
Move the docker exec call to a proper async task queue (or use asyncio.create_subprocess_exec) so it doesn't block the worker's event loop / GIL. This would prevent worker deaths from dropping in-flight execution launches.

Option D: Add execution recovery on worker restart
When a new worker starts (detected via Application startup complete), scan for executions in "running" state with no claude_session_id and either retry or fail them immediately instead of waiting for the polling deadline.

Environment

  • Trinity version: ccf573d
  • Uvicorn version: 0.37.0
  • Docker version: 28.3.3
  • OS: Debian GNU/Linux 12 (bookworm)
  • Python: 3.11.15

Related

Activity

  1. vybe commented on Mar 14, 2026

    @vybe
    ContributorAuthor

    Related: #132 (APScheduler max_instances skip — downstream impact when a stuck execution from this bug blocks the scheduler's polling loop)

  2. vybe commented on Mar 21, 2026

    @vybe
    ContributorAuthor

    Closing — resolved by dedicated scheduler service (trinity-scheduler). Scheduled task execution no longer runs in uvicorn workers, eliminating the root cause of worker deaths.

  3. added
    complexity-low
    on Jun 3, 2026
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

    complexity-lowpriority-p2type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions