ChannelManager#createChannel can return null when it runs out of free channels, the JavaDoc of AMQConnection#createChannel also says it may return null.
The following code in createChannel() and createChannel(int channelNumber)
|
Channel channel = cm.createChannel(this, channelNumber); |
|
metricsCollector.newChannel(channel); |
|
return channel; |
leads to an NPE in AbstractMetricsCollector#newChannel:
|
incrementChannelCount(channel); |
|
channel.addShutdownListener(cause -> closeChannel(channel)); |
|
connectionState(channel.getConnection()).channelState.put(channel.getChannelNumber(), new ChannelState(channel)); |
channel.addShutdownListener will fail with the NPE.
We've observed this through logs in one of our production services:
01-25 12:52:30 INFO c.r.c.impl.AbstractMetricsCollector - Error while computing metrics in newChannel: Cannot invoke "com.rabbitmq.client.Channel.addShutdownListener(com.rabbitmq.client.ShutdownListener)" because "channel" is null
ChannelManager#createChannelcan return null when it runs out of free channels, the JavaDoc ofAMQConnection#createChannelalso says it may returnnull.The following code in
createChannel()andcreateChannel(int channelNumber)rabbitmq-java-client/src/main/java/com/rabbitmq/client/impl/AMQConnection.java
Lines 598 to 600 in 4142f8d
leads to an NPE in
AbstractMetricsCollector#newChannel:rabbitmq-java-client/src/main/java/com/rabbitmq/client/impl/AbstractMetricsCollector.java
Lines 85 to 87 in 4142f8d
channel.addShutdownListenerwill fail with the NPE.We've observed this through logs in one of our production services: