Skip to content

fix(jsonrpc): suppress error responses for notifications - #4146

Merged
rodrodros merged 7 commits into
NethermindEth:mainfrom
arunimshukla:fix/notification-errors
Oct 8, 2026
Merged

rodrodros merged 7 commits into
NethermindEth:mainfrom
arunimshukla:fix/notification-errors

Conversation

@arunimshukla

Copy link
Copy Markdown
Contributor

Problem

JSON-RPC notifications are requests without an id, so the server must not send a response, including an error response. Juno's request dispatcher currently emits error responses for notification requests that use an unknown method or have invalid parameters.

Changes

  • Suppress error responses for unknown-method notifications.
  • Suppress error responses for invalid-params notifications.
  • Keep normal error responses for requests that include an id.
  • Add regression coverage for notification-only and mixed batches.

Validation

I reproduced the bug with four focused cases: unknown-method notification, invalid-params notification, a notification-only failing batch, and a mixed batch. The new cases fail on the base commit and pass after the fix.

go test -race ./jsonrpc ./utils/broadcast ./core/trie2/trieutils -count=1

All three packages pass with the race detector enabled.

Reference: https://www.jsonrpc.org/specification

@brbrr brbrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Please take a look at the inline comment.

Nit: the PR body lists utils/broadcast and core/trie2/trieutils under validation. Those packages are not touched, and are irrelevant to your changes.

Comment thread jsonrpc/server.go Resolved

@brbrr brbrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. One check is good, but the fix moved the whole dispatch into a nested if/else, and that brings its own problem:

  • tuple is declared up front and stays nil on both error paths. The only thing that stops tuple[errorIndex] from panicking is the if res.Error != nil return above it. That link is implicit, and the next person to edit this function will not see it.
  • The happy path now sits three levels deep.

Keep the gate in one place, but put it outside the dispatch instead of inside it. Something like:

  1. Move the body of handleRequest from res := &response{...} to the end into a new method callMethod(ctx, req) (*response, http.Header). Keep its original early returns as they were on main. Drop the error return value, it was always nil past isSane.
  2. Remove the res.ID == nil check from inside the dispatch.
  3. Leave handleRequest as:
if err := req.isSane(); err != nil {
      s.logger.Trace("Request sanity check failed", zap.Error(err))
      return nil, http.Header{}, err
}

res, header := s.callMethod(ctx, req)
if req.ID == nil { // notification
      s.logger.Trace("Notification received, no response expected")
      return nil, header, nil
}
return res, header, nil

@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.17%. Comparing base (5464fa0) to head (586f753).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4146      +/-   ##
==========================================
- Coverage   80.27%   80.17%   -0.11%     
==========================================
  Files         502      502              
  Lines       38341    38343       +2     
==========================================
- Hits        30779    30741      -38     
- Misses       7553     7593      +40     
  Partials        9        9              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@brbrr
brbrr force-pushed the fix/notification-errors branch from 8af8a35 to a525b35 Compare October 5, 2026 16:20
@brbrr

brbrr commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@arunimshukla can you please rebase the PR, to make sure the commits are verified (I've noted that you've set it up already on your end). Thanks!

@rodrodros
rodrodros merged commit 4c6b4d3 into NethermindEth:main Oct 8, 2026
18 checks passed
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.

3 participants