Skip to content

eth/filters: honor context cancellation in bor block-log range scan#2259

Draft
lucca30 wants to merge 1 commit into
developfrom
lmartins/filter-ctx-cancel
Draft

eth/filters: honor context cancellation in bor block-log range scan#2259
lucca30 wants to merge 1 commit into
developfrom
lmartins/filter-ctx-cancel

Conversation

@lucca30

@lucca30 lucca30 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

What

BorBlockLogsFilter.unindexedLogs scans a block range one sprint at a time but
never checked the request context, so a request whose context was cancelled —
the client disconnected, or a deadline fired — kept scanning the full range and
held its RPC worker until the range was exhausted.

Upstream go-ethereum performs this check at the top of its unindexedLogs loop
(eth/filters/filter.go); the bor block-log filter omitted it.

Change

Restore parity with a select { case <-ctx.Done(): ... } guard at the top of
the loop, so a range scan stops promptly once the caller is gone. With the
context now observed, any deadline attached upstream (e.g. an operator-configured
RPC timeout) also bounds the scan.

Why

Without the check, a long range query keeps consuming a worker after its result
can no longer be delivered, reducing the RPC server's effective capacity under
cancelled or abandoned requests. The fix is small and matches the canonical
go-ethereum loop.

Changes

  • eth/filters/bor_filter.go: add the context-cancellation check to the
    unindexedLogs scan loop.
  • eth/filters/bor_filter_test.go: add TestBorFilterHonorsContextCancellation
    and TestBorFilterHonorsContextDeadline.

Testing

  • go test ./eth/filters/ — all pass (28).
  • The new tests fail on the prior code (the loop ran 1001 block reads on an
    already-cancelled context and returned a nil error) and pass with the fix.

BorBlockLogsFilter.unindexedLogs iterated the full block range without ever
checking the request context, so a cancelled request (client disconnect or an
expired deadline) kept scanning and held its RPC worker until the whole range
was exhausted. Upstream go-ethereum eth/filters/filter.go performs this check
at the top of its unindexedLogs loop; the bor copy omitted it.

Add the same select{<-ctx.Done()} guard so a range scan stops promptly when
the caller is gone, and add tests covering both cancellation and deadline.
@sonarqubecloud

sonarqubecloud Bot commented Jun 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
38.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.40%. Comparing base (706b800) to head (01f3bff).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2259      +/-   ##
===========================================
- Coverage    53.41%   53.40%   -0.02%     
===========================================
  Files          896      896              
  Lines       159713   159721       +8     
===========================================
- Hits         85314    85302      -12     
- Misses       69071    69090      +19     
- Partials      5328     5329       +1     
Files with missing lines Coverage Δ
eth/filters/bor_filter.go 80.21% <100.00%> (+1.90%) ⬆️

... and 16 files with indirect coverage changes

Files with missing lines Coverage Δ
eth/filters/bor_filter.go 80.21% <100.00%> (+1.90%) ⬆️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant