[PHP] Hold pooled workers until streamed responses finish#3553
Conversation
7bd3012 to
f950217
Compare
13c1cb4 to
dfa2a4b
Compare
9f5b24e to
fe9b9c4
Compare
c2a6cd2 to
af2730f
Compare
7788ed1 to
1507232
Compare
af2730f to
2aaf83d
Compare
1507232 to
27303d6
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Prevents pooled PHP wasm workers from being returned to the pool while a streamed response is still being consumed by delaying release() until the stream’s finished promise settles.
Changes:
- Add
finished-aware release logic inObjectPoolProxyso instances remain checked out during streaming. - Add a unit test ensuring a second borrower blocks until the first streamed result finishes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/php-wasm/universal/src/lib/object-pool-proxy.ts | Delays releasing pooled instances until a returned streamed result’s finished promise settles. |
| packages/php-wasm/universal/src/lib/object-pool-proxy.spec.ts | Adds a regression test verifying the pool remains locked while a streamed result is unfinished. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Promise.resolve(finished).then( | ||
| () => release(instance), | ||
| () => release(instance) | ||
| ); |
There was a problem hiding this comment.
The Promise.resolve(finished).then(...) is intentionally not awaited/returned; in repos that use no-floating-promises, this will be flagged and can also make it easy to miss that errors inside release() would surface as an unhandled rejection. Consider explicitly marking it as intentionally detached (e.g., prefix with void) and using finally to avoid duplicating the release(instance) callback for both success and failure.
| Promise.resolve(finished).then( | |
| () => release(instance), | |
| () => release(instance) | |
| ); | |
| void Promise.resolve(finished).finally(() => release(instance)); |
#101) The vendored @wp-playground/cli + @php-wasm/universal tarballs (a build of WordPress/wordpress-playground#3494) worked around a worker-pool bug that returned PHP workers to the pool before their streamed response finished, causing intermittent 500s under concurrent e2e requests. That bug was fixed upstream (WordPress/wordpress-playground#3553) and shipped in the 3.1.2x line, so depend on the released package instead. - @wp-playground/cli: file:./vendor/...-pr3494.tgz -> ^3.1.36 - drop the @php-wasm/universal file: override (now resolves transitively) - remove the vendor/ tarballs - run the e2e Playground server with --workers=auto Verified: e2e 23/23 on 4 workers (no 5xx), php 140/140.
What it does
Keeps a borrowed pooled worker checked out until a streamed result finishes.
Rationale
ObjectPoolProxyreleased instances as soon as the proxied method returned. For streamed responses, the method returns before the stream is consumed, so another caller could reuse the same worker while the previous response was still active.Implementation
If the proxied result exposes a
finishedpromise, release the instance only after that promise settles. The new test covers the streamed-result lock behavior.Testing instructions
Run
npx nx test:vite php-wasm-universal -- object-pool-proxy.spec.ts, or use the CI matrix.