Repository navigation
fix(pool): uncaught-handler teardown (#101) + sendFile under reactor pool (#105) - #113
Merged
Merged
Conversation
…pool (#105) #101 — an uncaught exception from any request handler (H1/H2/H3/pool) leaked into the scheduler's EG(exception) and tripped a premature graceful shutdown of the whole worker (ZEND_ASYNC_REACTOR_LOOP_ALIVE assertion / hang at teardown). The handler-coroutine dispose now marks the exception consumed on both escalation paths (async_coroutine_finalize gates on EXCEPTION_HANDLED, coroutine_object_destroy on EXC_CAUGHT), so the peer gets a clean 500 / grpc-status and the worker survives. Fixed in all four dispose paths: http_connection.c (H1), http2_strategy.c, http3_dispatch.c, worker_dispatch.c (pool). #105 — under TRUE_ASYNC_SERVER_REACTOR_POOL=1, $response->sendFile() was silently dropped. The worker now marshals path + options as a RESPONSE_WIRE_SEND_FILE wire; the reactor rebuilds the request and runs the shared http_send_file_dispatch engine (opens the file, owns the fd, ETag/Range/304/MIME) — the same entry the non-pool H3 path uses. Also fixes a latent H3 stream-release bug this exposed: reactor_mode was derived from s->conn, which connection teardown nulls before force- releasing its streams, so a reactor stream torn down with its connection was misclassified non-pool — leaking the slab slot and double-freeing the worker-owned request. Release now reads a stable s->reactor_owned flag. Tests: h2/028-h2c-handler-throws, h3/049-h3-reactor-pool-sendfile.
This was referenced Jul 9, 2026
Closed
Contributor
CoverageTotal lines: 80.66% → 81.42% (+0.76 pp)
|
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.
Two related reactor-pool / teardown fixes.
#101 — uncaught handler exception aborts the worker (all protocols)
An uncaught exception from any request handler (H1/H2/H3/pool) leaked into the scheduler's
EG(exception)and tripped a prematurestart_graceful_shutdown()of the whole worker —ZEND_ASYNC_REACTOR_LOOP_ALIVE()assertion (debug) or a teardown hang (release). Not H3-specific; H1 survived only by teardown-timing luck.Root cause: two independent escalation paths in ext/async gate on different flags —
async_coroutine_finalizeonEXCEPTION_HANDLED,coroutine_object_destroyonEXC_CAUGHT. The handler dispose set neither.Fix: when a handler coroutine finishes with an exception (turned into a 500 / grpc-status), the dispose marks it consumed on both flags. Applied to all four dispose paths:
http_connection.c(H1),http2_strategy.c,http3_dispatch.c,worker_dispatch.c(pool).Regression test:
tests/phpt/server/h2/028-h2c-handler-throws.phpt.#105 — sendFile() silently dropped under the reactor pool
Under
TRUE_ASYNC_SERVER_REACTOR_POOL=1,$response->sendFile()produced no delivery — the worker render path had no send-file case.Fix: the worker marshals path + option snapshot into a new
RESPONSE_WIRE_SEND_FILEwire (raw bytes, PHP-free arena); the reactor rebuilds thehttp_send_file_request_tand runs the sharedhttp_send_file_dispatchengine — opens the file on the reactor, owns/closes the fd, honours ETag/Range/304/MIME. Same entry the non-pool H3 path uses. Reactor pool is H3-only today, so only the H3 apply is wired.Latent core bug this exposed (also fixed):
http3_stream_releasederivedreactor_modefroms->conn, but connection teardown nullss->connbefore force-releasing its live streams — so a reactor stream torn down with its connection was misclassified non-pool, leaking the slab slot (thehttp3_stream_pool_cleanupassertion) and runninghttp_request_destroyon the worker-freed request (UAF). Release now reads a stables->reactor_ownedflag set at stream creation.Regression test:
tests/phpt/server/h3/049-h3-reactor-pool-sendfile.phpt(byte integrity across the 16 KiB chunk boundary).Testing
Broad suite green — 196 tests, 0 failures across h3 / reactor_pool / sendfile / h1 / h2 / grpc / core.