Skip to content

fix(microservices): keep nats status updates alive when a listener throws - #18108

Merged
kamilmysliwiec merged 1 commit into
masterfrom
fix/nats-status-loop
Oct 12, 2026
Merged

kamilmysliwiec merged 1 commit into
masterfrom
fix/nats-status-loop

Conversation

@kamilmysliwiec

Copy link
Copy Markdown
Member

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

ServerNats and ClientNats start their status loop with void this.handleStatusUpdates(...). If anything throws while a status is handled, for example a listener registered with server.on('disconnect', ...) / client.on('reconnect', ...), the loop ends (no further disconnect/reconnect statuses are tracked) and the error becomes an unhandled rejection, which terminates the process with Node's default --unhandled-rejections=throw.

Follow-up to #18100, which removed one trigger (this.options.debug with no options) but not the weakness itself.

What is the new behavior?

  • Each status is handled in its own try/catch: the error is logged and the loop moves on to the next status.
  • A failing status iterator is caught at the call site and logged instead of rejecting unhandled.

Does this PR introduce a breaking change?

  • No

Other information

The diff is mostly re-indentation (git diff -w shows the actual change). The four new unit tests fail on master (two of them with unhandled rejections).

…rows

The status loop was started with `void`, so an error thrown while handling a status, e.g. by a listener registered with `on()`, ended the status updates and surfaced as an unhandled rejection, which stops the process by default. Each status is now handled in its own try/catch, and a failing status iterator is logged.
@kamilmysliwiec
kamilmysliwiec merged commit ee3300c into master Oct 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant