Skip to content

Conversation

@klim0v
Copy link
Contributor

@klim0v klim0v commented Nov 8, 2025

The problem is related to a race condition when using the versionToUse variable in concurrent goroutines:

Problem Description

At line 246 (versionToUse = GetPayloadV1), a local variable versionToUse is modified, which is captured by the closure of all running goroutines (lines 159-314). This leads to the following issue:

  1. N goroutines are launched for N relays with versionToUse == GetPayloadV2
  2. Relay A doesn't support V2 API → returns an error (StatusCode >= 400)
  3. Goroutine A modifies the shared variable to versionToUse = GetPayloadV1 (line 246)
  4. Relay B supports V2 API → returns a valid response with StatusCode == 202 (Accepted)
  5. Goroutine B tries to process the response, but due to the variable change, enters the condition if versionToUse == GetPayloadV1 (line 266)
  6. Parsing of a valid V2 response occurs as V1, leading to a decoding error

Technical Details

All goroutines share a single versionToUse variable captured through closure. When one goroutine modifies its value (line 246), it immediately affects the processing logic in other goroutines (lines 266-302), which may be at different execution stages.

Consequences

  • Valid V2 responses will be parsed as V1
  • A decoding error will occur (line 288)
  • Valid payload will be rejected
  • Potentially may lead to a missed slot

When multiple relays are configured and some don't support getPayloadV2, a race condition occurs where one goroutine modifies the shared versionToUse variable, affecting response parsing in other concurrent goroutines.

This causes valid V2 responses to be incorrectly parsed as V1, leading to decoding errors and potential missed slots.

Fixed by capturing versionToUse in each goroutine's scope, ensuring each relay request maintains its own independent version state throughout the request-response lifecycle.
@bharath-123 bharath-123 self-requested a review November 9, 2025 08:06
@bharath-123 bharath-123 merged commit 93d68d4 into flashbots:develop Nov 9, 2025
2 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.

2 participants