-
-
Notifications
You must be signed in to change notification settings - Fork 290
Description
Overview
When using AmqpConnection.request(), if the RabbitMQ connection is lost while a request is pending timeout, an unhandled AggregateError [ECONNREFUSED] crashes the application. This error occurs before the timeout error is thrown and cannot be caught with a standard try/catch block.β
Steps to Reproduce
- Configure RabbitMQ module with valid connection settings
- Make a request using
amqp.requestwith a timeout (e.g., 5000ms) - While the request is waiting to timeout, close/stop the RabbitMQ broker
- Observe the unhandled
AggregateError [ECONNREFUSED]that crashes the application
Let me know whether should I prepare a reproduction repository, but similar case is in this issue already and it seems to have a reproduction repo.
Expected Behavior
The connection loss error should be caught and handled gracefully, allowing the application to continue running. The timeout error should be thrown and catchable by the caller's try/catch block.β
Actual Behavior
An unhandled AggregateError [ECONNREFUSED] is thrown, followed by the timeout error, crashing the entire application.
Error message:
AggregateError [ECONNREFUSED]:
at internalConnectMultiple (node:net:1139:18)
at afterConnectMultiple (node:net:1714:7)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)
node_modules/@golevelup/nestjs-rabbitmq/lib/amqp/connection.js:212
throw new Error(`Failed to receive response within timeout of ${timeout}ms for exchange "${requestOptions.exchange}" and routing key "${requestOptions.routingKey}"`);
^
Error: Failed to receive response within timeout of 5000ms for exchange "test-exchange" and routing key "*"
at <anonymous> (node_modules/@golevelup/nestjs-rabbitmq/src/amqp/connection.ts:431:15)
at <anonymous> (node_modules/rxjs/src/internal/operators/map.ts:57:33)
at OperatorSubscriber.OperatorSubscriber._this._next (node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (node_modules/rxjs/src/internal/Subscriber.ts:71:12)
at <anonymous> (node_modules/rxjs/src/internal/operators/throwIfEmpty.ts:50:22)
at OperatorSubscriber.OperatorSubscriber._this._next (node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (node_modules/rxjs/src/internal/Subscriber.ts:71:12)
at <anonymous> (node_modules/rxjs/src/internal/operators/take.ts:60:26)
at OperatorSubscriber.OperatorSubscriber._this._next (node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (node_modules/rxjs/src/internal/Subscriber.ts:71:12)
Environment
Node.js version: v23.11.0
@golevelup/nestjs-rabbitmq version: 6.0.1
NestJS version: 11.1.2