Skip to content

Commit

Permalink
Unlock the write lock of the UnAckedMessageTracker before call redeli…
Browse files Browse the repository at this point in the history
…verUnacknowledgedMessages (apache#10768)

The deadlock will happen in following steps:

1. The client internal thread got the consumer instance lock when call internalBatchReceiveAsync
2. The timer thread got the write lock of the UnAckedMessageTracker and then waiting on the consumer instance lock when call redeliverUnacknowledgedMessages
3. The client internal thread try to get the write lock of the UnAckedMessageTracker when adding unacked messages

The deadlock happens.

The fix is ensure the timer thread unlock the write lock before call redeliverUnacknowledgedMessages
  • Loading branch information
codelipenghui authored Jun 1, 2021
1 parent 0136176 commit c4ee288
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,12 @@ public void run(Timeout t) throws Exception {
headPartition.clear();
timePartitions.addLast(headPartition);
} finally {
try {
if (messageIds.size() > 0) {
consumerBase.onAckTimeoutSend(messageIds);
consumerBase.redeliverUnacknowledgedMessages(messageIds);
}
timeout = client.timer().newTimeout(this, tickDurationInMs, TimeUnit.MILLISECONDS);
} finally {
writeLock.unlock();
writeLock.unlock();
if (messageIds.size() > 0) {
consumerBase.onAckTimeoutSend(messageIds);
consumerBase.redeliverUnacknowledgedMessages(messageIds);
}
timeout = client.timer().newTimeout(this, tickDurationInMs, TimeUnit.MILLISECONDS);
}
}
}, this.tickDurationInMs, TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit c4ee288

Please sign in to comment.