-
Notifications
You must be signed in to change notification settings - Fork 584
Closed
Description
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)
rabbitmq-java-client/src/main/java/com/rabbitmq/client/impl/AMQConnection.java
Lines 598 to 600 in 4142f8d
Channel channel = cm.createChannel(this, channelNumber); | |
metricsCollector.newChannel(channel); | |
return channel; |
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
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