Skip to content

Commit 4d6847f

Browse files
committed
Clean state in AutorecoveringChannel#abort
Fixes #661
1 parent 04a5e5c commit 4d6847f

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.rabbitmq.client.*;
1919
import com.rabbitmq.client.impl.AMQCommand;
20+
import com.rabbitmq.client.impl.recovery.Utils.IoTimeoutExceptionRunnable;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223

@@ -69,33 +70,41 @@ public Channel getDelegate() {
6970

7071
@Override
7172
public void close() throws IOException, TimeoutException {
72-
try {
73-
delegate.close();
74-
} finally {
75-
for (String consumerTag : consumerTags) {
76-
this.connection.deleteRecordedConsumer(consumerTag);
77-
}
78-
this.connection.unregisterChannel(this);
79-
}
73+
executeAndClean(() -> delegate.close());
8074
}
8175

8276
@Override
8377
public void close(int closeCode, String closeMessage) throws IOException, TimeoutException {
84-
try {
85-
delegate.close(closeCode, closeMessage);
86-
} finally {
87-
this.connection.unregisterChannel(this);
88-
}
78+
executeAndClean(() -> delegate.close(closeCode, closeMessage));
8979
}
9080

9181
@Override
9282
public void abort() throws IOException {
93-
delegate.abort();
83+
try {
84+
executeAndClean(() -> delegate.abort());
85+
} catch (TimeoutException e) {
86+
// abort() ignores exceptions
87+
}
9488
}
9589

9690
@Override
9791
public void abort(int closeCode, String closeMessage) throws IOException {
98-
delegate.abort(closeCode, closeMessage);
92+
try {
93+
executeAndClean(() -> delegate.abort(closeCode, closeMessage));
94+
} catch (TimeoutException e) {
95+
// abort() ignores exceptions
96+
}
97+
}
98+
99+
private void executeAndClean(IoTimeoutExceptionRunnable callback) throws IOException, TimeoutException {
100+
try {
101+
callback.run();
102+
} finally {
103+
for (String consumerTag : consumerTags) {
104+
this.connection.deleteRecordedConsumer(consumerTag);
105+
}
106+
this.connection.unregisterChannel(this);
107+
}
99108
}
100109

101110
@Override

0 commit comments

Comments
 (0)