test: object-bound handler closure survives the worker-pool fan-out#34
Merged
Conversation
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.
Contributor
CoverageTotal lines: 80.86% → 80.86% (+0.00 pp) No per-file changes. |
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.
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 viatransfer_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 aNULL$this— every worker died with SIGSEGV.Root cause was in
ext/async—closure_transfer_obj()snapshotted the closure withoutfci_cache.object. Fixed in true-async/php-async#123 ("preserve a closure's bound$thisacross 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, runssetWorkers(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$thiscan be reconstructed.Passes with the php-async fix; segfaults the workers without it.