Repository navigation
fix(rpc): stop a JSON-RPC batch whose caller has disconnected - #1610
Conversation
A batch ran every one of its calls even after the caller had closed the connection, so nobody was left to read the answers. The handler now checks the request's context before each call and stops once it is cancelled. A single call, or the call of a batch that is already running, still runs to its end: the methods do not watch their context. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit a464e56) · triage: low |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The implementation correctly stops a JSON-RPC batch before starting another call after the HTTP request context is canceled, and the added tests cover both direct handler cancellation and real TCP disconnects. Two non-blocking issues remain: the new Serve-level test lacks the leaktest guard used by its sibling tests, and golangci-lint fails on the new US-English spelling check for “cancelled.”
💬 2 nitpick(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.1-sol(effort low) — This is a small, well-contained HTTP JSON-RPC request-cancellation change with focused tests and straightforward behavior to verify. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 91% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— tenderdash-consensus-security (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions are optional: fix them forward in a later PR rather than pushing another round just for them.
- Address every current finding in one push: self-review the full diff first, and don't push piecemeal.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `rpc/jsonrpc/server/http_server_test.go`:
- [NITPICK] rpc/jsonrpc/server/http_server_test.go:96-98: Serve-level cancellation test does not check for goroutine leaks
This test starts both the Serve goroutine and Serve's internal shutdown-watcher goroutine, but it does not register the leaktest cleanup used by TestMaxOpenConnections and TestServeTLS in the same file. The goroutines exit on the current path, but without the guard a future shutdown regression could leave them behind unnoticed. Add the existing leaktest check for consistency and coverage of this lifecycle test.
- [NITPICK] rpc/jsonrpc/server/http_server_test.go:94-95: golangci-lint rejects the new spelling in the test comment
The new comment uses “cancelled” at line 95, while .golangci.yml configures misspell with the US locale. The golangci-lint check is therefore failing on code introduced by this PR; change the spelling to “canceled” before merge.
| func TestServeStopsBatchWhenCallerDisconnects(t *testing.T) { | ||
| ln, err := net.Listen("tcp", "localhost:0") | ||
| require.NoError(t, err) |
There was a problem hiding this comment.
💬 Nitpick: Serve-level cancellation test does not check for goroutine leaks
This test starts both the Serve goroutine and Serve's internal shutdown-watcher goroutine, but it does not register the leaktest cleanup used by TestMaxOpenConnections and TestServeTLS in the same file. The goroutines exit on the current path, but without the guard a future shutdown regression could leave them behind unnoticed. Add the existing leaktest check for consistency and coverage of this lifecycle test.
| func TestServeStopsBatchWhenCallerDisconnects(t *testing.T) { | |
| ln, err := net.Listen("tcp", "localhost:0") | |
| require.NoError(t, err) | |
| t.Cleanup(leaktest.Check(t)) |
source: glm-5.3-flash (phase1-reviewer: general)
| // A caller that closes its connection in the middle of a batch ends the batch: the call in | ||
| // progress sees its context cancelled, and the calls after it do not run. |
There was a problem hiding this comment.
✅ Resolved at
a464e56a; see the replies below.
💬 Nitpick: golangci-lint rejects the new spelling in the test comment
The new comment uses “cancelled” at line 95, while .golangci.yml configures misspell with the US locale. The golangci-lint check is therefore failing on code introduced by this PR; change the spelling to “canceled” before merge.
| // A caller that closes its connection in the middle of a batch ends the batch: the call in | |
| // progress sees its context cancelled, and the calls after it do not run. | |
| // A caller that closes its connection in the middle of a batch ends the batch: the call in | |
| // progress sees its context canceled, and the calls after it do not run. |
source: glm-5.3-flash (phase1-reviewer: general)
There was a problem hiding this comment.
Resolved (re-reviewed at a464e56a): Your spelling correction at http_server_test.go:95 addresses the reported lint failure, and golangci-lint passes on this head.
|
Bots are done — your move: post |
Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
At a464e56, the only change since the previous review corrects the test comment's spelling, and golangci-lint passes. Static inspection confirms cancellation is checked before each batch call; no new production defect was found. CI's tests (00) failure is unrelated: the unchanged consensus load test charged 137 work units against a timing-dependent requirement of more than 137.1863; the remaining build, test, and lint checks pass.
💬 1 nitpick(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Still open from earlier rounds (1)
- 💬 Nitpick: Serve-level cancellation test does not check for goroutine leaks —
rpc/jsonrpc/server/http_server_test.go:96(thread)
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.1-sol(effort low) — This is a small, well-contained HTTP JSON-RPC request-context cancellation change with focused tests and no critical consensus, cryptographic, storage, or funds-related behavior. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 97% left, weekly 91% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— tenderdash-consensus-security (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions are optional: fix them forward in a later PR rather than pushing another round just for them.
- Address every current finding in one push: self-review the full diff first, and don't push piecemeal.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `rpc/jsonrpc/server/http_server_test.go`:
- [NITPICK] rpc/jsonrpc/server/http_server_test.go:96: Serve-level cancellation test does not check for goroutine leaks
(carried; thread: https://github.com/dashpay/tenderdash/pull/1610#discussion_r4524741272)
|
Bots are done — your move: post |
TL;DR: A JSON-RPC batch now stops running its calls once the caller has closed the connection.
User story
As a service that reads blocks from Tenderdash over JSON-RPC (such as DAPI), I want Tenderdash to stop working on a batch I have given up on, so that the load I put on the node ends when I stop waiting.
Scenario
Base flow
A client posts a batch of calls, for example
block,block_resultsandcommitfor ten heights, which is 30 calls. Its own caller goes away or its deadline passes, so it closes the connection before the answer arrives.Actual behavior
Tenderdash runs every remaining call of the batch and then tries to write an answer nobody reads. A client cannot tell from its side when that work is over, so it cannot safely count a request against a concurrency limit only for as long as it waits.
Expected behavior
The batch stops before its next call, and nothing is written.
Detailed discussion
What was done
rpc/jsonrpc/server/http_json_handler.go: the batch loop checks the request's context before each call and returns once it is cancelled. Go's HTTP server cancels that context when the client's connection closes.block,block_results,commitand the rest) do not watch their context. So the work left behind by a caller is now at most one call, not the rest of the batch.Testing
TestRPCBatchStopsWhenCallerIsGone(http_json_handler_test.go): a batch of three calls with the caller staying, leaving before the first call, during the first and during the second. Without the fix the last three cases fail.TestServeStopsBatchWhenCallerDisconnects(http_server_test.go): the same throughServeon a real TCP connection that the client closes during the first call. The call sees its context cancelled and the two calls after it do not run.go test ./rpc/jsonrpc/...passes locally on macOS arm64.gofmtandgo vetare clean for the package. The full test suite and the linters were not run locally.Breaking changes
None. A caller that stays connected gets the same answer as before.
Prior work
Attribution
🤖 Generated with Claude Code
PR Hygiene ·
a464e56/self-reviewedrpc/jsonrpc/server/http_json_handler.go,rpc/jsonrpc/server/http_json_handler_test.go,rpc/jsonrpc/server/http_server_test.go) — approved by lklimekWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.