[ISSUE #10575] Fix race condition between scanResponseTable and processResponseCommand#10576
Open
wang-jiahua wants to merge 1 commit into
Open
[ISSUE #10575] Fix race condition between scanResponseTable and processResponseCommand#10576wang-jiahua wants to merge 1 commit into
wang-jiahua wants to merge 1 commit into
Conversation
… processResponseCommand processResponseCommand used get+remove (non-atomic) to retrieve ResponseFuture from responseTable. scanResponseTable used iterator.remove(). If the response arrived between scanResponseTable's remove and processResponseCommand's get, the response would be logged as 'not matched any request' and silently dropped. The callback would fire with timeout instead of success, even though the broker had successfully processed the request. Fix: Use ConcurrentHashMap.remove(key) in both methods. This is atomic: either processResponseCommand gets the future (and executes success callback), or scanResponseTable gets it (and executes timeout callback), but never both and never neither.
3c89a5a to
c100a62
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #10576 +/- ##
=============================================
- Coverage 48.26% 48.18% -0.09%
+ Complexity 13433 13415 -18
=============================================
Files 1378 1378
Lines 100817 100817
Branches 13040 13041 +1
=============================================
- Hits 48660 48579 -81
- Misses 46211 46274 +63
- Partials 5946 5964 +18 ☔ 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.
Which Issue(s) This PR Fixes
Fixes #10575
Brief Description
processResponseCommandusedresponseTable.get(opaque)+responseTable.remove(opaque)(non-atomic) to retrieve ResponseFuture.scanResponseTableusediterator.remove(). If the response arrived betweenscanResponseTable's remove andprocessResponseCommand's get, the response was logged asnot matched any requestand silently dropped.Fix: Use
ConcurrentHashMap.remove(key)(atomic) in both methods. EitherprocessResponseCommandgets the future (success callback) orscanResponseTablegets it (timeout callback), but never both and never neither.How Did You Implement It
processResponseCommand: Changed
responseTable.get(opaque)+responseTable.remove(opaque)to a singleresponseTable.remove(opaque)call.scanResponseTable: Changed
it.remove()toresponseTable.remove(next.getKey())and added a null check on the return value.How to Verify It
Reproduction: 256 threads, 50ms timeout, 1MB commitlog, single send thread pool. In 2 minutes, 776
not matched any requestwarnings appeared in clientremoting.log— all withcode=0(SEND_OK) and valid msgId/queueOffset. After applying this fix, the warnings should disappear.Existing tests:
NettyRemotingAbstractTest(5 tests) all pass.