Skip to content

Commit e1f2c8e

Browse files
michaelklishinacogoluegnes
authored andcommitted
AutorecoveringConnection.maybeDeleteRecordedAutoDeleteExchange does not need to acquire a lock on this.consumers
It most likely was a copy-paste artefact introduced back in 2013-2014. AutorecoveringConnection.maybeDeleteRecordedAutoDeleteQueue does need to lock this.consumers as conditional queue deletion does need to check the number of known consumers on that queue. 1aad565 addressed a potential deadlock caused by the unsafe order of lock acquisitions. In #648 another similar issue was discovered which #649 tried to address by acquiring a lock on this.consumers early. However, exchange cleanup does not need to lock this.consumers as it does not mutate it. Closes #648. (cherry picked from commit 5c3fce8)
1 parent 051c30d commit e1f2c8e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/main/java/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,15 +1032,13 @@ void maybeDeleteRecordedAutoDeleteQueue(String queue) {
10321032
}
10331033

10341034
void maybeDeleteRecordedAutoDeleteExchange(String exchange) {
1035-
synchronized (this.consumers) {
1036-
synchronized (this.recordedExchanges) {
1037-
if(!hasMoreDestinationsBoundToExchange(Utility.copy(this.recordedBindings), exchange)) {
1038-
RecordedExchange x = this.recordedExchanges.get(exchange);
1039-
// last binding where this exchange is the source is gone, remove recorded exchange
1040-
// if it is auto-deleted. See bug 26364.
1041-
if(x != null && x.isAutoDelete()) {
1042-
deleteRecordedExchange(exchange);
1043-
}
1035+
synchronized (this.recordedExchanges) {
1036+
if(!hasMoreDestinationsBoundToExchange(Utility.copy(this.recordedBindings), exchange)) {
1037+
RecordedExchange x = this.recordedExchanges.get(exchange);
1038+
// last binding where this exchange is the source is gone, remove recorded exchange
1039+
// if it is auto-deleted. See bug 26364.
1040+
if(x != null && x.isAutoDelete()) {
1041+
deleteRecordedExchange(exchange);
10441042
}
10451043
}
10461044
}

0 commit comments

Comments
 (0)