Skip to content

test: object-bound handler closure survives the worker-pool fan-out#34

Merged
EdmondDantes merged 3 commits into
mainfrom
test/worker-pool-bound-handler
May 21, 2026
Merged

test: object-bound handler closure survives the worker-pool fan-out#34
EdmondDantes merged 3 commits into
mainfrom
test/worker-pool-bound-handler

Conversation

@EdmondDantes
Copy link
Copy Markdown
Contributor

Regression test for a closure-transfer bug surfaced through HttpServer.

Background

With setWorkers(N) > 1, HttpServer::start() replicates the config + handler to each worker thread via transfer_obj. A handler closure bound to an object ($obj->method(...), or a closure that uses $this) lost that binding in transit: the worker rebuilt an unbound closure and the first request dereferenced a NULL $this — every worker died with SIGSEGV.

Root cause was in ext/asyncclosure_transfer_obj() snapshotted the closure without fci_cache.object. Fixed in true-async/php-async#123 ("preserve a closure's bound $this across thread transfer").

The server code itself was correct; this PR only adds the regression test that would have caught it at the server level.

Test

tests/phpt/server/core/044-worker-pool-bound-handler.phpt — registers an object-bound handler closure, runs setWorkers(2), and curls the port 16×, asserting every response carries data read through $this. setBootloader() defines the bound object's class inside each worker so the transferred $this can be reconstructed.

Passes with the php-async fix; segfaults the workers without it.

Note: requires true-async/php-async#123 in the PHP build used by CI.

Regression test for the closure-transfer bug fixed in true-async/php-async
("preserve a closure's bound $this across thread transfer"): with
setWorkers > 1 the handler is replicated to worker threads, and a closure
bound to an object lost its $this on the way — the first request then
NULL-dereferenced it and every worker died with SIGSEGV.

setBootloader() defines the bound object's class inside each worker so the
transferred $this can be reconstructed. Requires the php-async fix to pass.
The regression test depends on true-async/php-async#123; until that fix
is in the CI PHP build a $this-bound handler closure loses its binding
across the worker transfer and the test fails. XFAIL keeps CI green in
both states (expected-fail before the fix, pass after); the section is
to be removed once php-async#123 is merged.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Coverage

Total lines: 80.86% → 80.86% (+0.00 pp)

No per-file changes.

@EdmondDantes EdmondDantes merged commit e2ce297 into main May 21, 2026
5 checks passed
@EdmondDantes EdmondDantes deleted the test/worker-pool-bound-handler branch May 21, 2026 08:15
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