Repository navigation
cln-rpc: verify response id and recover cleanly from cancelled calls - #9763
Open
daywalker90 wants to merge 1 commit into
Open
daywalker90 wants to merge 1 commit into
daywalker90 wants to merge 1 commit into
Conversation
`ClnRpc::call_raw_request` incremented `next_id` on every request but never checked the `id` field of the response read from the socket. If a call was cancelled mid-read (e.g., via `tokio::time::timeout` or `tokio::select!`), its delayed response stayed in the Unix socket buffer and was silently returned to the next RPC call, permanently shifting all subsequent responses off by one. Similarly, cancelling mid-write could leave a partially flushed frame buffered in `FramedWrite`, and socket read errors were discarded with `|_|`. Track incomplete writes with `dirty_write` and flush any buffered frame before sending the next request, verify `msg["id"]` against the sent `id`, discard stale responses from earlier cancelled numeric request IDs (`got < expected`) and notifications without an `id`, return an error on unexpected/mismatched IDs, and include the underlying read error in the returned `RpcError`. Fix the mismatched mock response `"id": "1"` in `test::call_raw_request` and add regression tests for post-cancellation desync, out-of-order stale responses, unexpected response IDs, and mid-write cancellation. Changelog-Fixed: cln-rpc: verify JSON-RPC response IDs and flush interrupted writes so cancelling an RPC future (e.g., via `timeout` or `select!`) no longer desynchronizes subsequent calls on the same `ClnRpc`.
This branch has not been deployed
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.
ClnRpc::call_raw_requestincrementednext_idon every request but never checked theidfield of the response read from the socket. If a call was cancelled mid-read (e.g., viatokio::time::timeoutortokio::select!), its delayed response stayed in the Unix socket buffer and was silently returned to the next RPC call, permanently shifting all subsequent responses off by one. Similarly, cancelling mid-write could leave a partially flushed frame buffered inFramedWrite, and socket read errors were discarded with|_|.Track incomplete writes with
dirty_writeand flush any buffered frame before sending the next request, verifymsg["id"]against the sentid, discard stale responses from earlier cancelled numeric request IDs (got < expected) and notifications without anid, return an error on unexpected/mismatched IDs, and include the underlying read error in the returnedRpcError.Fix the mismatched mock response
"id": "1"intest::call_raw_requestand add regression tests for post-cancellation desync, out-of-order stale responses, unexpected response IDs, and mid-write cancellation.Changelog-Fixed: cln-rpc: verify JSON-RPC response IDs and flush interrupted writes so cancelling an RPC future (e.g., via
timeoutorselect!) no longer desynchronizes subsequent calls on the sameClnRpc.