fix(pool): healthcheck timer must not block graceful worker shutdown (true-async/server#93)#181
Merged
Conversation
…es not block a graceful worker shutdown (true-async/server#93) The pool healthcheck timer is a background heartbeat, but pool_start_healthcheck_timer started it as a normal reactor event, so it counted toward active_event_count. An idle pool (e.g. a warmed PDO pool with ATTR_POOL_HEALTHCHECK_INTERVAL > 0) therefore kept ZEND_ASYNC_REACTOR_LOOP_ALIVE() true after all coroutines were cancelled on graceful shutdown. On worker hot-reload the scheduler fiber then tripped ZEND_ASSERT(REACTOR_LOOP_ALIVE() == false) in fiber_entry (debug build); on release the idle heartbeat needlessly kept the retiring worker's loop alive. The HIDDEN flag's own documentation lists "background timers (health checks)" as the canonical case, so mark the timer HIDDEN — it still fires; it just no longer counts as application work for deadlock/loop-alive accounting.
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.
Problem
Under a debug build, hot-reloading workers can trip a scheduler assert:
Reproduced deterministically: a worker bootloader that warms an async PDO connection pool with
PDO::ATTR_POOL_HEALTHCHECK_INTERVAL > 0, thenreload(). With the interval set to0(no timer) the reload is clean — isolating the pool's healthcheck timer as the cause.Root cause
pool_start_healthcheck_timer()created the background heartbeat timer as a normal reactor event, solibuv_timer_startincrementedactive_event_count. On graceful shutdownstart_graceful_shutdown()cancels coroutines, but nothing owns/closes this timer — the pool is only disposed later at PDO object teardown. SoZEND_ASYNC_REACTOR_LOOP_ALIVE()(active_event_count > 0 && uv_loop_alive) stayedtruewhile the scheduler fiber finalized:ZEND_ASSERTinfiber_entry.The
ZEND_ASYNC_EVENT_F_HIDDENflag exists for exactly this — its doc names "Background timers (e.g., garbage collection, health checks)" as the canonical case — but the pool timer never set it.Fix
Mark the healthcheck timer
HIDDENright after creation. The timer still fires (HIDDEN only gates theactive_event_countaccounting, notuv_timer_start); it just no longer counts as application work for loop-alive / deadlock detection.Verification
pdo_pool_*,pool_*): 0 failed (17 passed, 8 skipped — need mysql/pgsql).