fix(session): prevent reported-provider/pairing race in GetReportedPr…#2249
Conversation
Review Summary by QodoPrevent reported-provider/pairing race in GetReportedProviders
WalkthroughsDescription• Move lock acquisition before reportedProviders read in GetReportedProviders • Prevents race condition between GetReportedProviders and UpdateAllProviders • Eliminates "Failed to find reported provider" error at epoch boundaries • Add comprehensive test reproducing and validating the race condition fix Diagramflowchart LR
A["GetReportedProviders<br/>reads reportedProviders"] -->|without lock| B["UpdateAllProviders<br/>resets reportedProviders"]
B -->|rebuilds pairing| C["Lookup fails<br/>stale data"]
D["Fix: acquire lock<br/>before reading"] -->|atomic operation| E["Consistent snapshot<br/>no race"]
File Changes1. protocol/lavasession/consumer_session_manager.go
|
Code Review by Qodo
1. Sleep-based race test flaky
|
…oviders Move csm.lock.RLock acquisition to before reading reportedProviders so that UpdateAllProviders cannot reset reportedProviders and rebuild pairing between the epoch check and the pairing lookup. This eliminates the "Failed to find a reported provider in pairing list" error seen at epoch boundaries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8d481d0 to
1e1ec42
Compare
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
User description
…oviders
Move csm.lock.RLock acquisition to before reading reportedProviders so that UpdateAllProviders cannot reset reportedProviders and rebuild pairing between the epoch check and the pairing lookup. This eliminates the "Failed to find a reported provider in pairing list" error seen at epoch boundaries.
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...
!in the type prefix if API or client breaking changemainbranchReviewers 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...
Generated description
Below is a concise technical summary of the changes proposed in this PR:
Ensure
ConsumerSessionManagerobtainscsm.lock.RLockbefore accessing reported providers and epoch soGetReportedProvidersnever sees a snapshot that is inconsistent with the rebuilt pairing state. Add a regression test that reproduces the epoch-transition race betweenGetReportedProvidersandUpdateAllProvidersto confirm the locking fix.GetReportedProvidersby takingcsm.lock.RLockbefore reading reported providers so pairing lookups never race withUpdateAllProvidersresetting the provider list.Modified files (1)
Latest Contributors(2)
GetReportedProvidersruns, ensuring the fix returns an empty result instead of stale reported providers.Modified files (1)
Latest Contributors(2)