amqplib icon indicating copy to clipboard operation
amqplib copied to clipboard

TypeError: Cannot read property 'fields' of null

Open grahamjenson opened this issue 11 years ago • 5 comments

On an connection.on("error", function(error) ... listener I am very occasionally getting a TypeError: Cannot read property 'fields' of null

I am not sure why this happens, I am adding more logging to try get a the stack trace, it probably breaking about 1 every few million messages, so not a critical bug, just annoying.

grahamjenson avatar Aug 10 '15 12:08 grahamjenson

I wonder if it's a consumer getting a null -- this happens when RabbitMQ cancels the consumer (http://www.rabbitmq.com/consumer-cancel.html). Well, we shall see -- let me know when the logging turns something up. Thanks!

squaremo avatar Aug 11 '15 21:08 squaremo

I'm getting the same thing in the debug window - cannot read property "close" of null. Im connecting to a Rabbit 3.3.4 server.

pmclean1964 avatar Mar 29 '16 17:03 pmclean1964

This occurs because your consumer function is called with a null message when the queue which it consumes is either deleted or in a cluster scenario, the node on which the queue is located is failing/failed, which will cause the consumption to be cancelled. Basically if your consumer is cancelled by RabbitMQ (i.e the server), the consumer callback will be invoked with null.

So within the consumer function/callback, a check for if the message is null can be used to detect if the queue was either deleted or if the consumer was cancelled.

The RabbitMQ Consumer Cancel Notification docs, this similar Github issue and the Amqplib docs on channel.consume were all good pointers in resolving and understanding the issue.

darthchudi avatar May 07 '19 00:05 darthchudi

@squaremo

You could actually close this issue.

Uzlopak avatar Nov 04 '21 00:11 Uzlopak

I am closing this issue, because I no longer use rabbitmq. I am not sure if this has been fixed however.

grahamjenson avatar Nov 04 '21 00:11 grahamjenson