Skip to content

Async errors from consume callback become unhandled promise rejections #20

@iifawzi

Description

@iifawzi

Summary

The amqp consume callback in RunMQConsumerCreator.runProcessor is async but its returned Promise is never awaited by rabbitmq-client. Any error that escapes the processor chain (notably from RunMQExceptionLoggerProcessor, which re-throws after logging) becomes an unhandled rejection.

Where

  • src/core/consumer/RunMQConsumerCreator.ts:60-89
  • src/core/consumer/processors/RunMQExceptionLoggerProcessor.ts:8-21 (rethrows)
  • src/core/consumer/processors/RunMQFailedMessageRejecterProcessor.ts:8-15 (only catches errors from inner consumer, not from its own nack call)

Failure mode

  • Channel closes mid-shutdown → nack() throws → escapes RunMQFailedMessageRejecterProcessor (its catch only protects the inner consume call) → propagates up → unhandled rejection.
  • On Node 15+ with default settings, this terminates the worker process.
  • Even before termination: messages are stuck in unacked state until channel timeout, no recovery.

Proposed fix

Wrap the entire inner work of the consume callback in a try/catch that logs and never rethrows:

await consumerChannel.consume(name, async (msg) => {
    if (!msg) return;
    try {
        const rabbitmqMessage = new RabbitMQMessage(...);
        await new RunMQExceptionLoggerProcessor(...).consume(rabbitmqMessage);
    } catch (e) {
        this.logger.error('Unhandled error in consumer chain', { cause: e });
        // do NOT rethrow — broker will redeliver on channel close
    }
});

Acceptance criteria

  • Consumer callback never produces an unhandled rejection, even when ack/nack itself throws.
  • Test: simulated channel-close during nack does not crash the consumer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcriticalCritical severityreleasedresilienceResilience / failure-mode issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions