Fixing EndpointPool concurrency issues - #690
Open
Myllyenko wants to merge 1 commit into
Open
Conversation
pessimizeEndpoint looked up recordsByEndpoint and tested knownEndpoint.isPessimized() before taking any lock. Both the map reference and the priority field it reads are non-volatile and are replaced or written under the write lock by setNewState and pessimize, so those reads had no happens-before edge with the writers. Two threads failing on the same endpoint could each miss the other's update and redo the full re-sort and rescan of the pool, and a lookup against a stale map could pessimize an entry that is no longer part of the current state. Keep the cheap "already pessimized" short circuit but perform it under the read lock, then re-validate under the write lock before mutating. needToRunDiscovery is written under the write lock but read by the discovery scheduler thread with no lock at all, so a pessimization-driven discovery could go unnoticed indefinitely. Make it volatile. This is a memory visibility fix; the interleavings involved are not reproducible deterministically, so it comes without a new test.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #690 +/- ##
=========================================
Coverage 71.91% 71.91%
+ Complexity 3474 3473 -1
=========================================
Files 390 390
Lines 16220 16225 +5
Branches 1698 1699 +1
=========================================
+ Hits 11664 11669 +5
Misses 3904 3904
Partials 652 652 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pessimizeEndpointlooked uprecordsByEndpointand testedknownEndpoint.isPessimized()before taking any lock. Both the map reference and the priority field it reads are non-volatile and are replaced or written under the write lock bysetNewStateandpessimize, so those reads had no happens-before edge with the writers. Two threads failing on the same endpoint could each miss the other's update and redo the full re-sort and rescan of the pool, and a lookup against a stale map could pessimize an entry that is no longer part of the current state.needToRunDiscoveryis written under the write lock but read by the discovery scheduler thread with no lock at all, so a pessimization-driven discovery could go unnoticed indefinitely.