fix(rpc): reject pending calls when target disconnects - #34974
fix(rpc): reject pending calls when target disconnects#34974HEETMEHTA18 wants to merge 4 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
When the target Worker emits 'error' (uncaught exception) or
'messageerror', all pending RPC call() promises hung forever.
- Store { resolve, reject } in pending map (was just resolve)
- Add 'error' and 'messageerror' event listeners on target
- Add closed flag to reject calls made after disconnect
- Add try/catch around postMessage for DataCloneError
- Guard against post-disconnect calls returning new hanging promises
Verified against a real Bun Worker that throws at import time:
- Worker uncaught throw fires 'error' event -> rejectAll runs
- Calls made after 'closed' reject immediately
|
Updated the branch based on review feedback: Changes made:
Test results: Typecheck: 29/29 packages pass. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #34981
Type of change
What does this PR do?
When a Worker emits
error(uncaught exception) ormessageerror, all pending RPCcall()promises hung forever because no listener existed to reject them.Changes:
{ resolve, reject }in pending map instead of justresolveerrorandmessageerrorevent listeners on the targetclosedflag — calls made after disconnect reject immediately instead of hanging againtry/catcharoundpostMessageforDataCloneErrorVerified with a real Bun Worker that throws at import time:
errorevent →rejectAll()runsclosedreject immediately with "RPC target disconnected"terminate()does NOT fire events in Bun — that case is handled by caller-side timeoutsHow did you verify your code works?
Also verified:
terminate()in Bun fires no events (see test/worker-events.test.ts), so this fix covers uncaught throws which do fireerror.Typecheck: 29/29 packages pass.
Checklist