Skip to content

Fix unsafe client selection in ClientPool - #265

Merged
pk910 merged 2 commits into
ethpandaops:masterfrom
damilolaedwards:fix/clientpool-selection-safety
Jul 31, 2026
Merged

Fix unsafe client selection in ClientPool#265
pk910 merged 2 commits into
ethpandaops:masterfrom
damilolaedwards:fix/clientpool-selection-safety

Conversation

@damilolaedwards

Copy link
Copy Markdown
Contributor

GetClient's round-robin branch read the shared cursor and indexed the current candidate slice with it before checking that the cursor was still in range for that slice. Because the candidate set can be smaller on a later call than it was when the cursor last advanced (a different client group, a type exclusion, a client toggling enabled), this could index past the end of the slice and panic. The cursor is now clamped before it is read, and the duplicate round-robin logic that lived under both the explicit case and the default fallback is merged into one path.

Also fixes the client health check writing goodClients without holding selectionMutex, while GetClient only reads it under that lock. A write with no lock at all gives the reader no real protection, so the two could race on the slice header and hand back a stale length paired with a reallocated backing array.

Adds tests covering round-robin selection across a smaller group, a shrinking pool, the byIndex control path, and a concurrent write/read check for the lock fix.

damilolaedwards and others added 2 commits July 30, 2026 15:31
GetClient's round-robin branch read the shared cursor and indexed the
current candidate slice with it before checking that the cursor was
still in range for that slice. Because the candidate set can be smaller
on a later call than it was when the cursor last advanced (a different
client group, a type exclusion, a client toggling enabled), this could
index past the end of the slice and panic. The cursor is now clamped
before it is read, and the duplicate round-robin logic that lived under
both the explicit case and the default fallback is merged into one path.

Also fixed the client health check writing goodClients without holding
selectionMutex, while GetClient only reads it under that lock. A write
with no lock at all gives the reader no real protection, so the two
could race on the slice header and hand back a stale length paired with
a reallocated backing array.
@pk910
pk910 enabled auto-merge July 31, 2026 00:34
@pk910
pk910 merged commit 6e37984 into ethpandaops:master Jul 31, 2026
7 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