Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning upon deleting queue using RabbitMQ Microservice #5683

Closed
zvaehn opened this issue Nov 10, 2020 · 6 comments · Fixed by #5801
Closed

UnhandledPromiseRejectionWarning upon deleting queue using RabbitMQ Microservice #5683

zvaehn opened this issue Nov 10, 2020 · 6 comments · Fixed by #5801

Comments

@zvaehn
Copy link

zvaehn commented Nov 10, 2020

Bug Report

(node:16452) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property 'content' of 'message' as it is null.
    at ServerRMQ.handleMessage (/Users/user/custom-nest-project/nest-microservice-error/node_modules/@nestjs/microservices/server/server-rmq.js:71:17)
    at channel.consume.noAck.noAck (/Users/user/custom-nest-project/nest-microservice-error/node_modules/@nestjs/microservices/server/server-rmq.js:65:51)
    at ConfirmChannel.BaseChannel.dispatchMessage (/Users/user/custom-nest-project/nest-microservice-error/node_modules/amqplib/lib/channel.js:484:12)
    at ConfirmChannel.BaseChannel.handleCancel (/Users/user/custom-nest-project/nest-microservice-error/node_modules/amqplib/lib/channel.js:497:15)
    at ConfirmChannel.emit (events.js:310:20)
    at ConfirmChannel.C.accept (/Users/user/custom-nest-project/nest-microservice-error/node_modules/amqplib/lib/channel.js:409:17)
    at Connection.mainAccept [as accept] (/Users/user/custom-nest-project/nest-microservice-error/node_modules/amqplib/lib/connection.js:64:33)
    at Socket.go (/Users/user/custom-nest-project/nest-microservice-error/node_modules/amqplib/lib/connection.js:478:48)
    at Socket.emit (events.js:310:20)
    at emitReadable_ (_stream_readable.js:543:12)
    at processTicksAndRejections (internal/process/task_queues.js:83:21)
(node:16452) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:16452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Current behavior

If the RabbitMQ microservice is connected and the queue gets deleted the error message pops up.
I found no way to catch this exception.

Input Code

Zipped Code:
nest-microservice-error.zip

Repository:
https://github.com/zvaehn/nestjs-5683-reproduction-setup

run it by:

  • npm install
  • docker-compose up
  • npm run start:dev

Expected behavior

If you kill the custom_queue via lets say http://localhost:15672/#/queues the error message appears.
The application is still running though, but does not reassign the queue.

Possible Solution

I'd like to catch and react on this error.

Environment


"@nestjs/common": "^7.5.1",
"@nestjs/core": "^7.5.1",
"@nestjs/microservices": "^7.5.1",
"@nestjs/platform-express": "^7.5.1",
"amqp-connection-manager": "^3.2.1",
"amqplib": "^0.6.0",
@zvaehn zvaehn added the needs triage This issue has not been looked into label Nov 10, 2020
@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (as a Github/Gitlab repo)

@kamilmysliwiec kamilmysliwiec added needs clarification and removed needs triage This issue has not been looked into labels Nov 11, 2020
@zvaehn
Copy link
Author

zvaehn commented Nov 11, 2020

I've updated the Issue Description.
(https://github.com/zvaehn/nestjs-5683-reproduction-setup)

@zvaehn
Copy link
Author

zvaehn commented Nov 18, 2020

Did you have a chance to have a look at it?

@poulad
Copy link
Contributor

poulad commented Nov 26, 2020

I also faced this issue. Looking into a PR at the moment.

It seems when a queue that we are consuming is deleted, e.g. by a troublemaker broker admin, amqplib package does:

  1. Send a null message to the callback function consuming the messages on that queue. I think there is a bug in NestJS due to not handling consumeMsg === null scenario.
  2. After that single null message, channel is closed by the broker so we get close event for the channel object.

Since NestJS is using amqp-connection-manager, I expect it to run the setup function again when channel is closed which means deleted queue will be declared again based on the configurations provided.

poulad added a commit to poulad/nest that referenced this issue Nov 26, 2020
A null message is passed to callback when RabbitMQ queue is deleted. See nestjs#5683
@poulad
Copy link
Contributor

poulad commented Nov 26, 2020

I'm not sure if this is a expected behavior according to AMQP or RabbitMQ docs. Passing a null message to the callback like this could also be a bug in amqplib package.

@poulad
Copy link
Contributor

poulad commented Nov 26, 2020

Never mind, amqplib is behaving as expected according to its docs.

See Channel#consume

If the consumer is cancelled by RabbitMQ, the message callback will be invoked with null.

Also see amqp-node/amqplib#497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants