[PR #1563] [CLOSED] fix(serve): release requests after engine READY timeout #3535

Closed
opened 2026-11-07 14:42:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1563
Author: @hulkbig
Created: 10/8/2026
Status: ❌ Closed

Base: main ← Head: fix/startup-timeout-pipe-cleanup-1527-20261008


📝 Commits (1)

  • 5093130 fix(server): bound cleanup after engine startup timeout

📊 Changes

3 files changed (+411 additions, -55 deletions)

View changed files

📝 serve/server.py (+95 -55)
📝 serve/test_lifecycle.py (+1 -0)
➕ serve/test_startup_timeout.py (+315 -0)

📄 Description

Fixes #1527

Summary

The READY timeout kills the shell wrapper in the issue's reproducer, but its sleep child can keep stdout open. The reader thread remains blocked in readline(), and the request then blocks in stdout.close() waiting for that reader's lock. This prevents the existing retry/error path from returning a response.

What changed

  • Start the Strata engine in an owned session on POSIX and clean up its process group before reaping the leader. Group signaling is gated by the unreaped leader and serialized with Popen's wait lock, so a recycled process-group ID cannot be targeted.
  • Bound the reader join and defer stdout closure when the reader is still alive. Deferred cleanup captures the old process and reader, so it cannot close a replacement engine's stdout.
  • Initialize the existing admission state before the lazy-start return and preserve it across restarts. Raise EngineDied for startup failure so HTTP returns 503 with the actual timeout reason rather than 400 with a missing slot_cv error.
  • Add 16 startup/lifecycle regressions covering timeout cleanup, inherited writers, process-group safety, late READY, retries, HTTP error propagation and recovery. Update the existing lifecycle mock to specify that its reader has stopped.

The existing retry count and backoff are unchanged.

Validation

On Linux CPU, using the issue's exact bash/sleep 3600 stub and STRATA_ENGINE_READY_S=8:

  • Baseline reproduced the hang in stdout closure after the wrapper was killed.
  • Fixed cold startup returned the timeout error in 8.002 s.
  • A real HTTP request returned 503 with the timeout reason in 54.015 s: three 8-second startup attempts plus two 15-second backoffs.
  • After replacing the stub with a working one, the next request returned 200.

Focused tests:

.venv/bin/python -m unittest serve.test_startup_timeout serve.test_lifecycle serve.test_restart_waiters serve.test_fatal_recovery serve.test_control_cancel serve.test_quiet_cancel serve.test_server.UntimedReads -v

55 tests passed. Compile and diff whitespace checks also passed.

Full discovery:

.venv/bin/python -m unittest discover -s serve -p 'test_*.py'

609 tests ran, 11 skipped, with one error in test_server.AmdTelemetry.test_readings: this environment returns None from psutil.disk_io_counters(), which unchanged serve/telemetry.py dereferences. The same error reproduced on untouched base fb58e0d.

As a supplemental environment-adjusted check, full discovery was repeated with an in-process shim that preserves real disk counters when available and supplies zero read/write counters only when they are None. The unchanged rerun passed all 609 tests with 11 skips. Its first run had a sampler-thread-count timing failure in unchanged test_responses.NoLeakedSampler.test_server_close_ends_the_sampler. No repository source or test edits were made for the shim. The raw full suite is therefore not a clean pass in this environment.

Limits

  • No GPU, Windows or macOS runtime validation was performed.
  • If the leader was already reaped, or Popen does not expose the wait lock, group signaling is conservatively skipped. Deferred pipe cleanup still releases the caller, but surviving descendants may remain until they exit.
  • This addresses the startup cleanup/error path; it does not change the stall watchdog or retry policy.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1563 **Author:** [@hulkbig](https://github.com/hulkbig) **Created:** 10/8/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/startup-timeout-pipe-cleanup-1527-20261008` --- ### 📝 Commits (1) - [`5093130`](https://github.com/Niko1221/Strata/commit/5093130bec7a2df328ff6010e267bcee68333b3e) fix(server): bound cleanup after engine startup timeout ### 📊 Changes **3 files changed** (+411 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+95 -55) 📝 `serve/test_lifecycle.py` (+1 -0) ➕ `serve/test_startup_timeout.py` (+315 -0) </details> ### 📄 Description Fixes #1527 ## Summary The READY timeout kills the shell wrapper in the issue's reproducer, but its `sleep` child can keep stdout open. The reader thread remains blocked in `readline()`, and the request then blocks in `stdout.close()` waiting for that reader's lock. This prevents the existing retry/error path from returning a response. ## What changed - Start the Strata engine in an owned session on POSIX and clean up its process group before reaping the leader. Group signaling is gated by the unreaped leader and serialized with Popen's wait lock, so a recycled process-group ID cannot be targeted. - Bound the reader join and defer stdout closure when the reader is still alive. Deferred cleanup captures the old process and reader, so it cannot close a replacement engine's stdout. - Initialize the existing admission state before the lazy-start return and preserve it across restarts. Raise `EngineDied` for startup failure so HTTP returns 503 with the actual timeout reason rather than 400 with a missing `slot_cv` error. - Add 16 startup/lifecycle regressions covering timeout cleanup, inherited writers, process-group safety, late READY, retries, HTTP error propagation and recovery. Update the existing lifecycle mock to specify that its reader has stopped. The existing retry count and backoff are unchanged. ## Validation On Linux CPU, using the issue's exact bash/`sleep 3600` stub and `STRATA_ENGINE_READY_S=8`: - Baseline reproduced the hang in stdout closure after the wrapper was killed. - Fixed cold startup returned the timeout error in 8.002 s. - A real HTTP request returned 503 with the timeout reason in 54.015 s: three 8-second startup attempts plus two 15-second backoffs. - After replacing the stub with a working one, the next request returned 200. Focused tests: ```sh .venv/bin/python -m unittest serve.test_startup_timeout serve.test_lifecycle serve.test_restart_waiters serve.test_fatal_recovery serve.test_control_cancel serve.test_quiet_cancel serve.test_server.UntimedReads -v ``` 55 tests passed. Compile and diff whitespace checks also passed. Full discovery: ```sh .venv/bin/python -m unittest discover -s serve -p 'test_*.py' ``` 609 tests ran, 11 skipped, with one error in `test_server.AmdTelemetry.test_readings`: this environment returns `None` from `psutil.disk_io_counters()`, which unchanged `serve/telemetry.py` dereferences. The same error reproduced on untouched base `fb58e0d`. As a supplemental environment-adjusted check, full discovery was repeated with an in-process shim that preserves real disk counters when available and supplies zero read/write counters only when they are `None`. The unchanged rerun passed all 609 tests with 11 skips. Its first run had a sampler-thread-count timing failure in unchanged `test_responses.NoLeakedSampler.test_server_close_ends_the_sampler`. No repository source or test edits were made for the shim. The raw full suite is therefore not a clean pass in this environment. ## Limits - No GPU, Windows or macOS runtime validation was performed. - If the leader was already reaped, or Popen does not expose the wait lock, group signaling is conservatively skipped. Deferred pipe cleanup still releases the caller, but surviving descendants may remain until they exit. - This addresses the startup cleanup/error path; it does not change the stall watchdog or retry policy. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:42:11 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3535
No description provided.