Skip to content

fix: attach 'error' listeners on connections and channels - #56

Open
arsalan507 wants to merge 1 commit into
bitrix24:mainfrom
arsalan507:fix/error-listeners
Open

fix: attach 'error' listeners on connections and channels#56
arsalan507 wants to merge 1 commit into
bitrix24:mainfrom
arsalan507:fix/error-listeners

Conversation

@arsalan507

Copy link
Copy Markdown

Summary

Fixes #28.

Node's EventEmitter throws synchronously (crashing the process, since it's an uncaught exception) when an 'error' event is emitted with no registered listener. Before this change:

  • RabbitMQProducer.connect() attached no 'error' listener to either the connection or the channel.
  • RabbitMQConsumer.connect() attached one to the connection, but not to the channel.

So a broker bounce mid-publish, or a channel-level protocol error, could crash the whole host process instead of being logged and handled gracefully — same failure mode the existing connection-level consumer listener was already added to prevent.

Fix

Attach an 'error' listener (routed through safeErrorMessage, same as the existing connection-level listener) on:

  • both the connection and the channel in Producer.connect()
  • the channel in Consumer.connect() (the connection listener already existed)

Test plan

  • Extended the shared tests/_helpers/amqp-mock.ts FakeChannel with on() / emitError(), mirroring the existing FakeConnection support, so tests can register and trigger channel-level 'error' listeners.
  • Added regression tests in tests/producer.test.ts (connection + channel) and tests/consumer.test.ts (channel) asserting a listener is registered and that emitting 'error' logs via the configured logger without throwing. Verified all three fail against the pre-fix code (channel.on/connection.on never called with 'error') and pass after the fix.
  • pnpm lint, pnpm typecheck, pnpm test (78 passing), pnpm build all green.

Node's EventEmitter throws (crashing the process) when an 'error'
event has no listener. The producer had no listener on its connection
or channel at all; the consumer had one on the connection but not on
its channel. A broker bounce or channel-level protocol error could
therefore crash the whole host process instead of being logged and
handled.

Attach an 'error' listener (logs via safeErrorMessage) on both the
connection and the channel in Producer.connect() and Consumer.connect().

Extended the shared amqp-mock test helper (FakeChannel) with on()/
emitError() so tests can register and trigger channel-level 'error'
listeners, mirroring the existing FakeConnection support.

Fixes bitrix24#28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: no 'error' listeners on the producer connection or on any channel — a broker bounce crashes the host process

1 participant