Skip to content

NPE in AbstractMetricsCollector when channel limit is exceeded #944

@Dav1dde

Description

@Dav1dde

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions