Skip to content

fix(pool): uncaught-handler teardown (#101) + sendFile under reactor pool (#105) - #113

Merged
EdmondDantes merged 1 commit into
mainfrom
fix/h2-uncaught-teardown-leak
Jul 9, 2026
Merged

EdmondDantes merged 1 commit into
mainfrom
fix/h2-uncaught-teardown-leak

Conversation

@EdmondDantes

Copy link
Copy Markdown
Contributor

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 premature start_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_finalize on EXCEPTION_HANDLED, coroutine_object_destroy on EXC_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_FILE wire (raw bytes, PHP-free arena); the reactor rebuilds the http_send_file_request_t and runs the shared http_send_file_dispatch engine — 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_release derived reactor_mode from s->conn, but connection teardown nulls s->conn before force-releasing its live streams — so a reactor stream torn down with its connection was misclassified non-pool, leaking the slab slot (the http3_stream_pool_cleanup assertion) and running http_request_destroy on the worker-freed request (UAF). Release now reads a stable s->reactor_owned flag 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.

…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.
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Coverage

Total lines: 80.66% → 81.42% (+0.76 pp)

File Baseline Current Δ Touched
src/compression/http_compression_response.c 82.28% 83.07% +0.79 pp
src/core/http_connection.c 74.95% 75.02% +0.07 pp ●
src/core/http_protocol_handlers.c 80.00% 86.25% +6.25 pp
src/core/http_protocol_strategy.h 33.33% 66.67% +33.33 pp
src/core/response_wire.c 90.00% 95.33% +5.33 pp ●
src/core/worker_dispatch.c 67.60% 75.93% +8.33 pp ●
src/core/worker_registry.c 61.63% 65.12% +3.49 pp
src/http2/http2_strategy.c 79.35% 79.43% +0.07 pp ●
src/http3/http3_callbacks.c 78.56% 81.64% +3.08 pp
src/http3/http3_connection.c 81.43% 81.70% +0.27 pp
src/http3/http3_dispatch.c 73.01% 79.95% +6.94 pp ●
src/http3/http3_io.c 86.55% 89.09% +2.55 pp
src/http3/http3_listener.c 72.59% 76.88% +4.29 pp
src/http3/http3_steer.c 87.50% 100.00% +12.50 pp
src/http3/http3_stream.c 95.18% 96.34% +1.16 pp ●
src/http_server_class.c 68.65% 69.07% +0.41 pp
src/log/http_log.c 67.94% 68.29% +0.35 pp

@EdmondDantes
EdmondDantes merged commit 28f141f into main Jul 9, 2026
8 checks passed
@EdmondDantes
EdmondDantes deleted the fix/h2-uncaught-teardown-leak branch July 11, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant