fix(kad-dht): reset stream on RPC handler error#3509
Merged
tabcat merged 2 commits intoMay 16, 2026
Conversation
Abort the stream when an incoming message handler throws so the remote sees the failure immediately instead of waiting for a timeout. Also renames the orphaned rpc index test to .spec.ts so the runner picks it up.
Replace the redundant no-handler log with a single error log in the onIncomingStream catch so every handler failure is observable.
dozyio
approved these changes
May 15, 2026
Merged
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.
Description
When an incoming DHT message handler throws,
RPC.handleMessageswallowed the error and returned no response, leaving the stream open. The requesting peer then waited for a response until its request timed out (~10s) before the stream was torn down.The stream is now reset as soon as a handler throws.
handleMessagere-throws handler errors — and throws on an unknown message type — instead of swallowing them, andonIncomingStreamaborts the stream, so the remote peer sees the failure immediately.Notes & open questions
The kad-dht spec doesn't define how a node should respond to a request it can't fulfil — it only specifies echoing the request back on success. This follows go-libp2p, which resets the stream on any handler error. Before this change js-libp2p left the stream open and the requesting peer timed out.
test/rpc/index.node.tsis renamed toindex.spec.ts— the test runner only matches*.spec.*js, so asindex.node.tsneither its existing test nor the new one would run.Change checklist