Skip to content

Commit 498bcc2

Browse files
committed
Adding sanity check to ChannelManager.disconnectChannel...
... which leads to a testfailure that indicates that there is a race (or similar problem) in Channel.close: java.lang.IllegalStateException: We have attempted to create a disconnect a channel that's no longer in use. This should never happen. Please report this as a bug. at com.rabbitmq.client.impl.ChannelManager.disconnectChannel(ChannelManager.java:130) at com.rabbitmq.client.impl.AMQConnection.disconnectChannel(AMQConnection.java:117) at com.rabbitmq.client.impl.ChannelN.releaseChannelNumber(ChannelN.java:169) at com.rabbitmq.client.impl.ChannelN.close(ChannelN.java:365) at com.rabbitmq.client.impl.ChannelN.abort(ChannelN.java:307) at com.rabbitmq.client.impl.ChannelN.abort(ChannelN.java:300) at com.rabbitmq.client.test.BrokerTestCase.closeChannel(BrokerTestCase.java:124) at com.rabbitmq.client.test.BrokerTestCase.tearDown(BrokerTestCase.java:67)
1 parent 1191221 commit 498bcc2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public ChannelManager(int channelMax){
6666
channelNumberAllocator = new IntAllocator(1, channelMax);
6767
}
6868

69-
69+
7070
/**
7171
* Public API - Looks up an existing channel associated with this connection.
7272
* @param channelNumber the number of the required channel
7373
* @return the relevant channel descriptor
74-
* @throws UnknownChannelException if there is no Channel associated with the
74+
* @throws UnknownChannelException if there is no Channel associated with the
7575
* required channel number.
7676
*/
7777
public ChannelN getChannel(int channelNumber) {
@@ -100,7 +100,7 @@ public synchronized ChannelN createChannel(AMQConnection connection) throws IOEx
100100
}
101101

102102
public synchronized ChannelN createChannel(AMQConnection connection, int channelNumber) throws IOException {
103-
if(channelNumberAllocator.reserve(channelNumber))
103+
if(channelNumberAllocator.reserve(channelNumber))
104104
return createChannelInternal(connection, channelNumber);
105105
else
106106
return null;
@@ -110,10 +110,10 @@ private synchronized ChannelN createChannelInternal(AMQConnection connection, in
110110
if (_channelMap.containsKey(channelNumber)) {
111111
// That number's already allocated! Can't do it
112112
// This should never happen unless something has gone
113-
// badly wrong with our implementation.
113+
// badly wrong with our implementation.
114114
throw new IllegalStateException("We have attempted to"
115115
+ "create a channel with a number that is already in"
116-
+ "use. This should never happen. Please report this as a bug.");
116+
+ "use. This should never happen. Please report this as a bug.");
117117
}
118118
ChannelN ch = new ChannelN(connection, channelNumber);
119119
addChannel(ch);
@@ -126,7 +126,12 @@ private void addChannel(ChannelN chan) {
126126
}
127127

128128
public synchronized void disconnectChannel(int channelNumber) {
129-
_channelMap.remove(channelNumber);
129+
if (_channelMap.remove(channelNumber) == null)
130+
throw new IllegalStateException(
131+
"We have attempted to "
132+
+ "create a disconnect a channel that's no longer in "
133+
+ "use. This should never happen. Please report this as a bug.");
134+
System.err.println("DISCONN CH" + channelNumber);
130135
channelNumberAllocator.free(channelNumber);
131136
}
132137
}

0 commit comments

Comments
 (0)