Skip to content

fix: prevent consumer crash from nil pointer dereference in relay#2091

Merged
nimrod-teich merged 4 commits into
mainfrom
fix_panic_send_realy
Nov 20, 2025
Merged

fix: prevent consumer crash from nil pointer dereference in relay#2091
nimrod-teich merged 4 commits into
mainfrom
fix_panic_send_realy

Conversation

@AnnaR-prog

Copy link
Copy Markdown
Contributor

When all providers are blocked/unavailable, relay goroutines could crash with nil pointer dereference when accessing RelayPrivateData fields. This panic would crash the entire consumer process.

Changes:

  • Add nil check before dereferencing RelayPrivateData pointer
  • Add panic recovery in sendRelayToProvider goroutines
  • Treat panics as provider failures instead of crashing consumer
  • Include stack traces in error logs for debugging

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@github-actions

github-actions Bot commented Oct 23, 2025

Copy link
Copy Markdown

Test Results

2 957 tests  ±0   2 956 ✅ +1   34m 18s ⏱️ + 8m 7s
  126 suites ±0       1 💤 ±0 
    7 files   ±0       0 ❌  - 1 

Results for commit 3ebe306. ± Comparison against base commit c0b3e6e.

♻️ This comment has been updated with latest results.

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Oct 23, 2025
…outines

When all providers are blocked/unavailable, relay goroutines could crash
with nil pointer dereference when accessing RelayPrivateData fields.
This panic would crash the entire consumer process.

Changes:
- Add nil check before dereferencing RelayPrivateData pointer
- Add panic recovery in sendRelayToProvider goroutines
- Treat panics as provider failures instead of crashing consumer
- Include stack traces in error logs for debugging
…rash

Race condition occurred when multiple concurrent calls to sendRelayToProvider
shared the same protocolMessage.RelayPrivateData() object. Goroutines from
earlier calls would read corrupted data when newer calls modified SeenBlock
or Extensions fields, resulting in nil pointer dereference in bytes.Join.

Solution: Create deep copy of RelayPrivateData at function entry to ensure
complete isolation between concurrent calls. Each goroutine now receives its
own independent copy via parameter passing instead of closure capture.

Changes:
- Add deepCopyRelayPrivateData() helper to create independent copies
- Snapshot RelayPrivateData at sendRelayToProvider entry point
- Replace all protocolMessage.RelayPrivateData() accesses with local copy
- Pass local copy as parameter to goroutines for proper isolation
@nimrod-teich nimrod-teich merged commit b3b4092 into main Nov 20, 2025
48 of 49 checks passed
@nimrod-teich nimrod-teich deleted the fix_panic_send_realy branch November 20, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants