Skip to content

Commit 4aa43c0

Browse files
author
Alexandru Scvortov
committed
ensure resources are not released twice when closing channels
1 parent c706b3e commit 4aa43c0

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -184,29 +184,26 @@ public void releaseChannelNumber() {
184184

185185
Method method = command.getMethod();
186186

187-
if (method instanceof Channel.Close) {
188-
// Channel should always respond to Channel.Close
189-
// from the server
190-
releaseChannelNumber();
191-
ShutdownSignalException signal = new ShutdownSignalException(false,
192-
false,
193-
command,
194-
this);
195-
synchronized (_channelMutex) {
196-
try {
197-
processShutdownSignal(signal, true, false);
198-
quiescingTransmit(new Channel.CloseOk());
199-
} finally {
200-
notifyOutstandingRpc(signal);
201-
}
202-
}
203-
notifyListeners();
204-
return true;
205-
}
206187
if (isOpen()) {
207188
// We're in normal running mode.
208189

209-
if (method instanceof Basic.Deliver) {
190+
if (method instanceof Channel.Close) {
191+
releaseChannelNumber();
192+
ShutdownSignalException signal = new ShutdownSignalException(false,
193+
false,
194+
command,
195+
this);
196+
synchronized (_channelMutex) {
197+
try {
198+
processShutdownSignal(signal, true, false);
199+
quiescingTransmit(new Channel.CloseOk());
200+
} finally {
201+
notifyOutstandingRpc(signal);
202+
}
203+
}
204+
notifyListeners();
205+
return true;
206+
} else if (method instanceof Basic.Deliver) {
210207
Basic.Deliver m = (Basic.Deliver) method;
211208

212209
Consumer callback = _consumers.get(m.consumerTag);
@@ -273,7 +270,13 @@ public void releaseChannelNumber() {
273270
} else {
274271
// We're in quiescing mode.
275272

276-
if (method instanceof Channel.CloseOk) {
273+
if (method instanceof Channel.Close) {
274+
// We're already shutting down, so just send back an ok.
275+
synchronized (_channelMutex) {
276+
quiescingTransmit(new Channel.CloseOk());
277+
}
278+
return true;
279+
} else if (method instanceof Channel.CloseOk) {
277280
// We're quiescing, and we see a channel.close-ok:
278281
// this is our signal to leave quiescing mode and
279282
// finally shut down for good. Let it be handled as an

0 commit comments

Comments
 (0)