fix(thread_pool): graceful-shutdown a retiring sync worker so reload() completes (true-async/server#93)#177
Merged
Conversation
…) completes (true-async/server#93) A sync-mode pool worker (the HTTP server) posts its reload exit-token only after its scheduler drain (RUN_SCHEDULER_AFTER_MAIN) empties. The drain loops while any reactor handle is alive, so a never-ending coroutine the bootloader spawned into the worker's main scope — e.g. an async DB-pool healthcheck timer — keeps the drain (and the token, and thus HttpServer::reload()) hung forever. On the worker's `done:` exit, for sync-mode pools only, call start_graceful_shutdown() before the drain: it cancels the main-scope stragglers and arms the drain escape valve, so the worker retires and reload() proceeds. Gated on !coroutine_mode — coroutine-mode pools must keep draining their in-flight task coroutines instead (thread_pool/077). Also silence a GCC -O2 -Wmaybe-uninitialized false positive across the function's nested zend_try/setjmp blocks (loop-local task pointers + the zend_try macro's own __orig_bailout) with a GCC-only scoped pragma. Known follow-up: this exposes an intermittent SIGSEGV during rotation under stress (a persistent coroutine first-started with a NULL run-time cache) — documented in the server repo, not yet fixed.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A sync-mode pool worker posts its reload exit-token only after its scheduler drain (
RUN_SCHEDULER_AFTER_MAIN) empties. That drain loops while any reactor handle is alive, so a never-ending coroutine the bootloader spawned into the worker's main scope (e.g. an async DB-pool healthcheck timer) keeps the drain — and thusThreadPool::reload()— hung forever.On the worker's
done:exit, for sync-mode pools only (!coroutine_mode), callstart_graceful_shutdown()before the drain: it cancels the main-scope stragglers and arms the drain escape valve, so the worker retires andreload()proceeds. Gated to sync mode — coroutine-mode pools must keep draining their in-flight task coroutines (thread_pool/077).Also silences a GCC
-O2 -Wmaybe-uninitializedfalse positive across the function's nestedzend_try/setjmpblocks with a GCC-only scoped pragma.Tests:
thread_pool78/79, hot-reload phpt (server) 5/5, zero compiler warnings.Note: this exposes a separate, pre-existing bug — nested closures (
dynamic_func_defs) are shared across worker threads, so a bootloader-spawned nested-closure coroutine can hit a cross-threadrun_time_cacheuse-after-free during rotation. Tracked in #176; not addressed here.