Skip to content

Commit 987dea6

Browse files
Add a test and extra guard to prevent duplicate shutdown hooks that initial recovery
This ended up not being an issue in the Java client as much as in .NET.
1 parent cf7b7a9 commit 987dea6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ public void shutdownCompleted(ShutdownSignalException cause) {
356356
}
357357
};
358358
synchronized (this) {
359-
this.shutdownHooks.add(automaticRecoveryListener);
359+
if(!this.shutdownHooks.contains(automaticRecoveryListener)) {
360+
this.shutdownHooks.add(automaticRecoveryListener);
361+
}
360362
this.delegate.addShutdownListener(automaticRecoveryListener);
361363
}
362364
}

test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,20 @@ public void consumerRecovered(String oldConsumerTag, String newConsumerTag) {
432432

433433
}
434434

435+
public void testSubsequentRecoveriesWithClientNamedQueue() throws IOException, InterruptedException {
436+
String q = channel.queueDeclare(UUID.randomUUID().toString(), false, false, false, null).getQueue();
437+
438+
assertConsumerCount(0, q);
439+
channel.basicConsume(q, new DefaultConsumer(channel));
440+
441+
for(int i = 0; i < 10; i++) {
442+
assertConsumerCount(1, q);
443+
closeAndWaitForRecovery();
444+
}
445+
446+
channel.queueDelete(q);
447+
}
448+
435449
public void testQueueRecoveryWithManyQueues() throws IOException, InterruptedException, TimeoutException {
436450
List<String> qs = new ArrayList<String>();
437451
final int n = 1024;

0 commit comments

Comments
 (0)