nest icon indicating copy to clipboard operation
nest copied to clipboard

NestJS doesn't handle "Operation failed: QueueDeclare" error from amqplib

Open IvanKodak opened this issue 1 year ago • 1 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

I got a case when my RabbitMq was unavailable and after a few retries, NestJs was through an unhandled rejection error. I think that was caused because @nestjs/microservices doesn't handle this type of error from the amqplib.

I will attach the logs, that I have. Thanks in advance for helping

Minimum reproduction code

Currently I haven't reproduced this issue on local machine

Steps to reproduce

No response

Expected behavior

NestJS handles this error and tries to retry to connect to RabbitMq

Package

  • [ ] I don't know. Or some 3rd-party package
  • [ ] @nestjs/common
  • [ ] @nestjs/core
  • [X] @nestjs/microservices
  • [ ] @nestjs/platform-express
  • [ ] @nestjs/platform-fastify
  • [ ] @nestjs/platform-socket.io
  • [ ] @nestjs/platform-ws
  • [ ] @nestjs/testing
  • [ ] @nestjs/websockets
  • [ ] Other (see below)

Other package

No response

NestJS version

10.3.4

Packages versions

[Nest Platform Information]
platform-express version : 10.3.4
cache-manager version    : 2.2.1
event-emitter version    : 2.0.4
microservices version    : 10.3.4
sequelize version        : 10.0.1
schedule version         : 4.0.1
testing version          : 10.3.4
common version           : 10.3.4
config version           : 3.2.0
axios version            : 3.0.2
core version             : 10.3.4
cli version              : 10.3.2

Node.js version

20.11.0

In which operating systems have you tested?

  • [ ] macOS
  • [ ] Windows
  • [X] Linux

Other

Stack:

Error: Operation failed: QueueDeclare; 404 (NOT-FOUND) with message "NOT_FOUND - failed to perform operation on queue '<queue-name>' in vhost 'dev' due to timeout"
    at reply (/usr/app/node_modules/amqplib/lib/channel.js:133:29)
    at ConfirmChannel.C.accept (/usr/app/node_modules/amqplib/lib/channel.js:416:7)
    at Connection.mainAccept (/usr/app/node_modules/amqplib/lib/connection.js:63:33)
    at TLSSocket.go (/usr/app/node_modules/amqplib/lib/connection.js:486:48)
    at TLSSocket.emit (node:events:518:28)
    at TLSSocket.emit (node:domain:488:12)
    at emitReadable_ (node:internal/streams/readable:832:12)
    at processTicksAndRejections (node:internal/process/task_queues:81:21)


Trace:

{
  "file": "/usr/app/node_modules/amqplib/lib/channel.js",
  "line": 133,
  "column": 29,
  "native": false,
  "method": null,
  "function": "reply"
},
{
  "file": "/usr/app/node_modules/amqplib/lib/channel.js",
  "line": 416,
  "column": 7,
  "native": false,
  "method": "accept",
  "function": "ConfirmChannel.C.accept"
},
{
  "file": "/usr/app/node_modules/amqplib/lib/connection.js",
  "line": 63,
  "column": 33,
  "native": false,
  "method": "mainAccept",
  "function": "Connection.mainAccept"
},
{
  "file": "/usr/app/node_modules/amqplib/lib/connection.js",
  "line": 486,
  "column": 48,
  "native": false,
  "method": "go",
  "function": "TLSSocket.go"
},
{
  "file": "node:events",
  "line": 518,
  "column": 28,
  "native": false,
  "method": "emit",
  "function": "TLSSocket.emit"
},
{
  "file": "node:domain",
  "line": 488,
  "column": 12,
  "native": false,
  "method": "emit",
  "function": "TLSSocket.emit"
},
{
  "file": "node:internal/streams/readable",
  "line": 832,
  "column": 12,
  "native": false,
  "method": null,
  "function": "emitReadable_"
},
{
  "file": "node:internal/process/task_queues",
  "line": 81,
  "column": 21,
  "native": false,
  "method": null,
  "function": "processTicksAndRejections"
}

IvanKodak avatar Apr 18 '24 13:04 IvanKodak

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

kamilmysliwiec avatar Apr 19 '24 07:04 kamilmysliwiec

Same issue.

If RMQ pod drops my nest application errors.

[NestWinston] 1 - 6/14/2024, 9:56:47 AM ERROR unhandledRejection: Operation failed: QueueDeclare; 404 (NOT-FOUND) with message "NOT_FOUND - queue 'dlq_ks_provide_wallet.Bravo' in vhost 'dev' process is stopped by supervisor" Error: Operation failed: QueueDeclare; 404 (NOT-FOUND) with message "NOT_FOUND - queue 'dlq_ks_provide_wallet.Bravo' in vhost 'dev' process is stopped by supervisor" at reply (/usr/app/node_modules/amqplib/lib/channel.js:137:31) at ConfirmChannel.accept (/usr/app/node_modules/amqplib/lib/channel.js:315:9) at Connection.mainAccept (/usr/app/node_modules/amqplib/lib/connection.js:582:33) at TLSSocket.go (/usr/app/node_modules/amqplib/lib/connection.js:434:16) at TLSSocket.emit (node:events:519:28) at TLSSocket.emit (node:domain:488:12) at emitReadable_ (node:internal/streams/readable:832:12) at processTicksAndRejections (node:internal/process/task_queues:81:21) - {"error":{"code":404,"classId":50,"methodId":10},"stack":"Error: Operation failed: QueueDeclare; 404 (NOT-FOUND) with message "NOT_FOUND - queue 'dlq_ks_provide_wallet.Bravo' in vhost 'dev' process is stopped by supervisor"\n at reply (/usr/app/node_modules/amqplib/lib/channel.js:137:31)\n at ConfirmChannel.accept (/usr/app/node_modules/amqplib/lib/channel.js:315:9)\n at Connection.mainAccept (/usr/app/node_modules/amqplib/lib/connection.js:582:33)\n at TLSSocket.go (/usr/app/node_modules/amqplib/lib/connection.js:434:16)\n at TLSSocket.emit (node:events:519:28)\n at TLSSocket.emit (node:domain:488:12)\n at emitReadable_ (node:internal/streams/readable:832:12)\n at processTicksAndRejections (node:internal/process/task_queues:81:21)","rejection":true,"date":"Fri Jun 14 2024 09:56:47 GMT+0000 (Coordinated Universal Time)","process":{"pid":1,"uid":1000,"gid":1000,"cwd":"/usr/app","execPath":"/nodejs/bin/node","version":"v20.14.0","argv":["/nodejs/bin/node","/usr/app/dist/main"],"memoryUsage":{"rss":188100608,"heapTotal":106037248,"heapUsed":76675392,"external":5107639,"arrayBuffers":1461417}},"os":{"loadavg":[0.79,0.85,1],"uptime":2554919.14},"trace":[{"column":31,"file":"/usr/app/node_modules/amqplib/lib/channel.js","function":"reply","line":137,"method":null,"native":false},{"column":9,"file":"/usr/app/node_modules/amqplib/lib/channel.js","function":"ConfirmChannel.accept","line":315,"method":"accept","native":false},{"column":33,"file":"/usr/app/node_modules/amqplib/lib/connection.js","function":"Connection.mainAccept","line":582,"method":"mainAccept","native":false},{"column":16,"file":"/usr/app/node_modules/amqplib/lib/connection.js","function":"TLSSocket.go","line":434,"method":"go","native":false},{"column":28,"file":"node:events","function":"TLSSocket.emit","line":519,"method":"emit","native":false},{"column":12,"file":"node:domain","function":"TLSSocket.emit","line":488,"method":"emit","native":false},{"column":12,"file":"node:internal/streams/readable","function":"emitReadable_","line":832,"method":null,"native":false},{"column":21,"file":"node:internal/process/task_queues","function":"processTicksAndRejections","line":81,"method":null,"native":false}]}

DmytroShalaiev avatar Jun 14 '24 10:06 DmytroShalaiev