Skip to content

Commit f9c3018

Browse files
michaelklishinacogoluegnes
authored andcommitted
AutorecoveringConnection: clean up bindings of deleted exchanges
so that they (the bindings) do not reappear after connection recovery. Noticed while working on ruby-amqp/bunny#704. (cherry picked from commit aaff1cc)
1 parent acfcd83 commit f9c3018

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,12 @@ void recordExchange(String exchange, RecordedExchange x) {
10941094

10951095
void deleteRecordedExchange(String exchange) {
10961096
this.recordedExchanges.remove(exchange);
1097-
Set<RecordedBinding> xs = this.removeBindingsWithDestination(exchange);
1098-
for (RecordedBinding b : xs) {
1097+
Set<RecordedBinding> xs1 = this.removeBindingsWithDestination(exchange);
1098+
for (RecordedBinding b : xs1) {
1099+
this.maybeDeleteRecordedAutoDeleteExchange(b.getSource());
1100+
}
1101+
Set<RecordedBinding> xs2 = this.removeBindingsWithSource(exchange);
1102+
for (RecordedBinding b : xs2) {
10991103
this.maybeDeleteRecordedAutoDeleteExchange(b.getSource());
11001104
}
11011105
}
@@ -1172,6 +1176,20 @@ Set<RecordedBinding> removeBindingsWithDestination(String s) {
11721176
return result;
11731177
}
11741178

1179+
Set<RecordedBinding> removeBindingsWithSource(String s) {
1180+
final Set<RecordedBinding> result = new LinkedHashSet<>();
1181+
synchronized (this.recordedBindings) {
1182+
for (Iterator<RecordedBinding> it = this.recordedBindings.iterator(); it.hasNext(); ) {
1183+
RecordedBinding b = it.next();
1184+
if (b.getSource().equals(s)) {
1185+
it.remove();
1186+
result.add(b);
1187+
}
1188+
}
1189+
}
1190+
return result;
1191+
}
1192+
11751193
public Map<String, RecordedQueue> getRecordedQueues() {
11761194
return recordedQueues;
11771195
}

0 commit comments

Comments
 (0)