Repository navigation
fix: route invalid IPC JSON to request errors - #5586
Conversation
Reuses the scripted IPC peer in socket.timeout.test.ts instead of a copy of its connection helper. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f04d-baca-7631-b26d-fcb0d908dcd6 Co-authored-by: jxom <[email protected]>
Only JSON.parse is guarded now, so an error thrown by a response or subscription callback no longer rejects unrelated requests or forces a reconnect. Invalid JSON destroys the socket, which reports the error through its error event and closes the socket when it will not reconnect. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f04d-baca-7631-b26d-fcb0d908dcd6 Co-authored-by: jxom <[email protected]>
🦋 Changeset detectedLatest commit: 3692800 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Published pnpm add viem@pr-5586
pnpm add [email protected] |
tydavid5
left a comment
There was a problem hiding this comment.
Reviewed this against the issue it fixes, and it checks out.
Before, malformed JSON from an IPC peer threw inside the socket data listener, so a request could hang until timeout or crash the process. Wrapping the JSON.parse in a try and calling socket.destroy with the error is the right fix, because the socket error handler is already registered and that is what rejects the pending requests with the SyntaxError.
The test covers the exact case: it sends a truncated result, expects the request to reject as a SyntaxError, expects no pending requests left, and expects the socket destroyed. The second test is also worth keeping, it checks that a throwing response callback does not reject another pending request, and it restores the global uncaughtException listeners in a finally block.
Approving, the fix is correct and tested.
Supersedes #5574 by @yinbowen-dc (keeps their commit). Fixes #5562.
Malformed JSON from an IPC peer threw inside the socket
datalistener, crashing the process or leaving requests to time out. It now rejects pending requests, as the WebSocket transport does.On top of #5574:
JSON.parseis guarded. Errors thrown by response or subscription callbacks no longer reject unrelated requests or force a reconnect.socket.destroy(error), so the error still reaches pending requests through the socket'serrorevent and the socket is closed whenreconnect: false.socket.timeout.test.tsto reuse its IPC peer helper, and added a test for a throwing callback.ipctransport in the changeset.#5573 (IPC stray-brace framing) should land after or together with this PR: on its own it lets a stray
}followed by an invalid frame reachJSON.parseand throw uncaught.