Repository navigation
fix(microservices): run every event handler when a sibling completes empty - #17961
Merged
kamilmysliwiec merged 1 commit intoOct 1, 2026
Merged
kamilmysliwiec merged 1 commit into
kamilmysliwiec merged 1 commit into
Conversation
Handlers registered for the same event pattern are chained and joined with forkJoin. forkJoin completes without emitting as soon as one source completes empty, and it unsubscribes from the other sources. A handler that filtered the event out therefore cancelled a sibling handler that returned a cold observable, so its work never ran and the processing end hook fired before it. The docs say that Nest triggers all the handlers of a pattern in parallel. Default each branch of the join to undefined when it completes empty. The join still emits once, after every handler finishes, and an error in any handler still errors the join. An error that a sibling raised after an empty handler completed was lost before, because the join had already completed. It now reaches the transport, e.g. as a retriable Kafka error. Closes nestjs#17960
4 of 12 tasks
kamilmysliwiec
added a commit
that referenced
this pull request
Oct 16, 2026
Handlers registered for the same event pattern are joined with forkJoin, which unsubscribes from the other sources as soon as one of them errors. A guard, pipe or handler that failed for an event therefore cancelled its siblings: one that returned an observable or had an interceptor never ran, or was cut off mid-way, and nothing reported it. #17961 fixed the same for a handler that completes empty. Each handler now runs to the end, and the join fails with the first handler's error once all of them have finished. The error therefore reaches the transport, e.g. as a retriable Kafka error, only after the slowest sibling, and in registration order when several handlers fail. Discovered by Anthropic's OSS Scanner, as bug ANT-2026-Y9PB81SO.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
Issue Number: #17960
Closes #17960
Nest joins the handlers of one event pattern with
forkJoin.forkJoincompletes without emitting as soon as one source completes empty, and it unsubscribes from the other sources. So a handler that filters the event out cancels a sibling handler that returns a cold Observable. The work of that sibling never runs, and the processing end hook runs before it. The docs say that "Nest triggers all of them in parallel".asynchandlers are not affected, because Nest starts them eagerly.Measured with the repro on 12.1.2:
What is the new behavior?
Each branch of the join defaults to
undefinedwhen it completes empty. The join still emits once, after every handler finishes, and the end hook runs last. Nothing reads the joined value, soundefinedhas no effect on consumers.An error in a handler still errors the join, and it still cancels the other branches as before. The fix changes one more case, in a good direction. On Kafka, the join was already complete when a sibling raised an error after an empty handler, so Nest dropped that error. That error now reaches the transport as a retriable error.
The same repro against a local build of this branch:
Does this PR introduce a breaking change?
Handlers that the join cancelled now run to the end. Nothing exported changes.
Other information
The specs cover these cases:
Each
defaultIfEmptyhas a spec that fails without it.