Pull requests / #788
#788 serve: tolerate broken stdin pipes during engine cleanup
closed · @siddolo · 0 コメント · GitHub で見る
Setup & installServer & APIWindowsLinux
本文
## Problem `StrataEngine.close()` can raise `BrokenPipeError` from its `finally` block when closing buffered stdin after the native engine has exited. Closing the stream may flush pending data again, even if an earlier `flush()` failure was already handled. This was observed on Linux when stopping a custom systemd unit with `KillMode=control-group`, where the Python server and native engine receive SIGTERM together. The exception interrupts cleanup before stdout and the log are closed and the engine state is reset, causing an otherwise completed stop to exit with an error. ## Changes - Handle `OSError` from the final stdin close once the process has exited, allowing the remaining cleanup to finish. - Add a regression test using a real buffered OS pipe whose reader has closed, covering both an already-exited process and a pipe failure while sending QUIT. - Check that stdout and the log are closed, engine state is cleared, and repeated cleanup is harmless. The existing QUIT -> terminate -> kill sequence, EOF-before-wait behavior, and `EngineStuck` handling are preserved. ## Validation Both regression subcases fail with `BrokenPipeError` on the unmodified upstream code and pass with this fix. Validation was run on Linux with Python 3.12.3; the optional `jsonschema>=4.23,<5` dependency was installed for the schema tests. ```bash python -m unittest serve.test_lifecycle -v # 9 tests passed python -m unittest discover -s serve -p 'test_*.py' -q # 269 tests: 262 passed, 7 skipped (no pack tokenizer / Windows-only) git diff --check ```
関連リンク
インストール・モデル・リリースへの站内リンク。