Skip to content

Commit 00ef564

Browse files
committed
cleanup ReturnListener in close()
1 parent 8e9197e commit 00ef564

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/com/rabbitmq/client/RpcClient.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class RpcClient implements AutoCloseable {
9393
* @since 5.9.0
9494
*/
9595
private final Supplier<String> _correlationIdSupplier;
96+
private final ReturnListener _returnListener;
9697

9798
private String lastCorrelationId = "0";
9899

@@ -123,7 +124,7 @@ public RpcClient(RpcClientParams params) throws
123124

124125
_consumer = setupConsumer();
125126
if (_useMandatory) {
126-
this._channel.addReturnListener(returnMessage -> {
127+
this._returnListener = this._channel.addReturnListener(returnMessage -> {
127128
synchronized (_continuationMap) {
128129
String replyId = returnMessage.getProperties().getCorrelationId();
129130
BlockingCell<Object> blocker = _continuationMap.remove(replyId);
@@ -136,6 +137,8 @@ public RpcClient(RpcClientParams params) throws
136137
}
137138
}
138139
});
140+
} else {
141+
this._returnListener = null;
139142
}
140143
}
141144

@@ -157,6 +160,7 @@ private void checkNotClosed() throws IOException {
157160
public void close() throws IOException {
158161
if (this.closed.compareAndSet(false, true)) {
159162
_channel.basicCancel(_consumer.getConsumerTag());
163+
_channel.removeReturnListener(this._returnListener);
160164
}
161165
}
162166

0 commit comments

Comments
 (0)