Skip to content

fix(microservices): close both kafka client connections when one fails - #18027

Merged
kamilmysliwiec merged 2 commits into
nestjs:masterfrom
izg0820:fix/kafka-client-close-disconnects-consumer
Oct 8, 2026
Merged

kamilmysliwiec merged 2 commits into
nestjs:masterfrom
izg0820:fix/kafka-client-close-disconnects-consumer

Conversation

@izg0820

@izg0820 izg0820 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

ClientKafka.close() disconnects the producer and then the consumer. If the
producer's disconnect() rejects, the consumer is never disconnected and the
cached state (initialized, client, ...) is never reset.

Issue Number: N/A

What is the new behavior?

Both clients are disconnected with Promise.allSettled, and the state is
reset in a finally block. close() still rejects with the error, so the
caller still sees the failure.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This is the client part of #17990, split out after review. The server side
is left as is since its consumer-first order is needed for graceful shutdown.

@kamilmysliwiec kamilmysliwiec changed the title fix(microservices): disconnect the kafka consumer if the producer fails fix(microservices): close both kafka client connections when one fails Oct 8, 2026
@kamilmysliwiec
kamilmysliwiec merged commit 3b0973f into nestjs:master Oct 8, 2026
2 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.

2 participants