Repository navigation
[fix][broker] Fix deadlock in PendingAckHandleImpl - #18989
Conversation
michaeljmarshall
left a comment
There was a problem hiding this comment.
LGTM. Please be sure to update the PR description since the code no longer aligns with it.
| if (recoverTime.getRecoverStartTime() != 0L && recoverTime.getRecoverEndTime() == 0L) { | ||
| recoverTime.setRecoverEndTime(System.currentTimeMillis()); |
There was a problem hiding this comment.
Without the synchronized keyword in the method declaration, this conditional update to recoveredEndTime is subject to data races, and the variables will not be safely published to other threads. However, at this time, the recoverTime object is only used for stats, and we have a tendency to have relaxed requirements for stats. Perhaps it is fine. We could alternatively add methods to the class that ensure proper synchronization of updates. I don't feel strongly, except to mention that it is somewhat brittle to assume the variable will only ever be used by stats.
There was a problem hiding this comment.
You're totally right. This recoveryTime registers the time of the replay. It should be handled directly in the callback after the replay is completed. For the current usage, being non thread-safe is fine and I'd prefer leave it as is.
Those methods don't need synchronization at all since, at the moment, there's no data race for them.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18989 +/- ##
============================================
+ Coverage 46.35% 46.72% +0.36%
- Complexity 8939 10525 +1586
============================================
Files 597 706 +109
Lines 56858 69004 +12146
Branches 5905 7392 +1487
============================================
+ Hits 26357 32241 +5884
- Misses 27616 33173 +5557
- Partials 2885 3590 +705
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
(cherry picked from commit 22866bd)
(cherry picked from commit 22866bd)
Fixes #18988
Motivation
Based on stacktrace in the issue, in
PendingAckHandleImpl, if the first timependingAckHandleCompletableFutureis completed via the methodaddConsumerthePendingAckHandleImplobject is locked to the current thread because the methodcompleteHandleFutureis synchronized. TheaddConsumerthen locks thePersistentSubscription. In the reverse order the subscription closing procedure locks thePersistentSubscriptionobject and thenPendingAckHandleImpl.It's possible that if they run concurrently it ends up in a deadlock
Modifications
completeHandleFuturemethods. In this way thePendingAckHandleImplobject isn't locked in the stages chain.I haven't added tests since I wasn't able to reproduce it programmatically.
Verifying this change
Documentation
docdoc-requireddoc-not-neededdoc-complete