Repository navigation
fix(microservices): let the kafka client retry after a failed connect - #17816
kamilmysliwiec merged 1 commit into
Conversation
A rejected connection attempt stayed cached in `initialized`, so every later `connect()` call failed with the error of the first attempt until `close()` was called, even once the broker was reachable again. Reset the cached promise when the attempt fails and tear down the consumer and producer it managed to create, so the next call starts over.
micalevisk
left a comment
There was a problem hiding this comment.
Verified locally against a real broker as well as the unit suite. The fix does what it says and I could not find a hole in it.
What I checked
- The two new specs fail on the pre-PR source (
initializedstays a rejectedPromise) and pass with the fix; the wholeclient-kafka.spec.tspasses (40 tests).oxlint,prettier --check,tsc -b packages/microservicesand commitlint are clean. - Real kafkajs 2.2.4 against a throwaway
apache/kafka:3.9.0, in both consumer+producer andproducerOnlyMode: with the broker down,connect()rejects withKafkaJSNumberOfRetriesExceeded; a second call runs a fresh attempt (new error object;initialized,_consumer,_producerandclientare allnullafterwards); once the broker is up, the same client instance connects andemit()succeeds. The same script on the pre-PR source: the 2nd and 3rd calls return the identical cached error in 0 ms and the partial consumer (or producer, in producer-only mode) is left behind, exactly as described. - The ordering inside the
catchis right:initializedis cleared before the teardownawait, anddiscardPartialConnection()captures and nulls the fields synchronously, so aconnect()issued while the teardown is still in flight is neither clobbered by it nor sees stale instances.Promise.allSettledkeeps the original error as the one that surfaces. - This mirrors what
ClientNats#connect()already does withconnectionPromise(reset on rejection), and I found no earlier PR or issue where this was proposed or declined.
Not a breaking change: no exported surface changes; a failed connect() simply no longer poisons the instance until close(). No docs update needed.
Two non-blocking notes inline. Thanks for the clear write-up and the tests.
| * consumer that joined its group before the producer failed does not stay | ||
| * behind when the next attempt creates a new one. | ||
| */ | ||
| private async discardPartialConnection(): Promise<void> { |
There was a problem hiding this comment.
Non-blocking: close() (L128-136) now does this same teardown by hand. I'm not asking for it here, since close() deliberately awaits sequentially and lets disconnect errors propagate, but a follow-up could have close() delegate to this helper so the two don't drift.
| // has to try again once the broker is reachable, instead of failing | ||
| // forever with the error of the first attempt. | ||
| this.initialized = null; | ||
| await this.discardPartialConnection(); |
There was a problem hiding this comment.
FYI, no change needed: the event listeners are registered before connect(), so this teardown makes kafkajs emit DISCONNECT from the consumer and/or producer, and client.status now emits KafkaStatus.DISCONNECTED after a failed attempt (twice in the partial case). That is consistent with close() and semantically accurate; just noting it as a small observable change.
|
Thanks for the thorough review, and for testing it against a real broker in both modes. Agreed on both notes. I left Good catch on the |
The pull request and its diff come from the GitHub REST API over Node's fetch - two GETs, public and private repositories, one clear line for each failure (not found, rate limit, rejected token, a diff too large for GitHub, which names the --git range that reviews it instead). read_file and grep_repo are now offered only when the working directory is a checkout at the reviewed head, for --git as well as --pr. They read the working tree, so anywhere else they described different code. actions/checkout defaults to the test merge commit, so the step 4 workflow must ask for the head sha. The end-to-end run of all nine samples came first: six videos, three correct no-video runs, and two defects in the script, fixed. The first real pull request, nestjs/nest#17816, went to final.mp4 and produced a false positive about code the diff did not show. Q2 answered: the model runs on a self-hosted runner on a team machine. ADR-051. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…#17828) * fix(microservices): let the redis client retry after a failed connect When retryAttempts is configured and the retries are exhausted, the failed attempt stays cached in connectionPromise, so every later connect() call replays the cached "connection lost" rejection instead of trying again, even once the server is reachable. The clients the failed attempt managed to create are also left behind without being closed. Reset the cached promise when the attempt fails and quit the clients it created, so the next call starts over, same as the kafka client got in #17816 * fix(microservices): reset redis client state when ioredis gives up Resetting the cached promise in a catch around the attempt missed how the redis client manages its state: the "reconnecting", "ready" and "end" listeners rewrite connectionPromise and the pub/sub clients. - When ioredis gives up on a client ("end", retryAttempts not set or exhausted), drop the pair, reset connectionPromise and wasInitialConnectionSuccessful and disconnect the other client, so the next connect() call starts over. With retryAttempts set, a "Connection lost" rejection stayed cached forever, and without it the new sub client never got the response listener. - Only reset in the catch when no listener took over connectionPromise, so ioredis keeps retrying a failed first attempt in the background instead of the clients being quit right away. - Ignore the events of clients that are no longer the current pair, so a dropped or closed client shutting down late cannot re-cache a rejection, drop the new clients, or throw on a null sub client. - Keep the listeners registered with on() and attach them to every pair. Replace the no-op stubs in the tests with fakes that emit the connection events, and the test that relied on a closed port with one running a real ioredis client against a local server that drops every connection. * test(microservices): deflake the real ioredis retry test ioredis leaves a client that is disconnected while waiting to reconnect in the "reconnecting" status, so wait for the connection attempts to stop instead of for every client to reach "end". --------- Co-authored-by: Kamil Myśliwiec <mail@kamilmysliwiec.com>
…properly now Two findings settled without anyone having to look or listen. Re-running nestjs/nest#17816 from a clone at the PR's head, with read_file and grep_repo both offered, the Reviewer made zero tool calls and repeated the same false claim about a method the diff does not show. Withholding the tools without a checkout stays right, but offering them is not what fixes this: nothing obliges the model to read what it asserts. Recorded as roadmap step 19, not patched blind, because ADR-047 showed a one-sentence prompt edit can move recall by 0.2 for unrelated reasons. ADR-054. Kokoro's phonemizer answers the narration question without listening: toHaveBeenCalledOnce comes out as the right sounds run together into one word. normalizeForSpeech now restores the word boundaries for the voice only - subtitles keep the identifier - and runs of capitals stay whole. ADR-055. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…17865) * fix(microservices): let the rmq client retry after a failed connect When the first connection attempt fails, the rejection stays cached in connectionPromise, so every later connect() call replays the error of the first attempt until close() is called, even once the broker is reachable again. The connection manager the attempt created also stays behind and keeps retrying in the background Reset the cached promise when the attempt fails and close the manager it created, so the next call starts over, same as the kafka client got in #17816 and the redis client in #17828 * fix(microservices): keep a newer rmq connection when a stale one fails --------- Co-authored-by: Kamil Myśliwiec <mail@kamilmysliwiec.com>
On Ollama the answer's schema is a grammar over the whole reply, so a model offered tools could never call one: not one tool call in 270 traces. A provider now declares `schemaSilencesTools`, and an agent that asks for `lookBeforeAnswering` is offered its tools unconstrained, then asked for the answer exactly as before. Only the Reviewer with a checkout asks, since without one the tools repeat the prompt - so the golden set is untouched by construction (36 of 36 answers cached). The prompt with a checkout now says to read code before asserting what it does. Measured on nestjs/nest#17816 with step 16's seeds: the false positive appears in one run of five, and the model still calls no tool - one run made the same claim in the turn where it could have looked. Step 21 is planned: show the changed files instead of offering them. Taken under Bahman's instruction to continue (ADR-060). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a checkout, the Reviewer's user message now carries each changed file at the head revision after the diff - numbered, for reading only, capped at 20 KB per file and 32 KB in total, smallest files first. Both of the nestjs/nest#17816 false positives rested on code in a file the pull request changed, and step 19 showed the model will not read it when merely offered. Measured on that pull request at the same seeds: claims about code the diff does not show went from 2 of 4 to 0 of 4. One run misread code the diff does show, which no context would prevent. Checkout runs pay about three times the input and twice the Reviewer's time; a diff-only run is byte-identical, so the golden set came entirely from the cache. Taken under Bahman's instruction to continue (ADR-061). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| datasource | package | from | to | | ---------- | ------------------------ | ------ | ------ | | npm | @nestjs/common | 12.0.1 | 12.1.0 | | npm | @nestjs/core | 12.0.1 | 12.1.0 | | npm | @nestjs/platform-express | 12.0.1 | 12.1.0 | ## [v12.1.0](https://github.com/nestjs/nest/releases/tag/v12.1.0) ##### v12.1.0 (2026-09-23) ##### Bug fixes - `core` - [#17838](nestjs/nest#17838) fix(core): inherit optional ctor params when the ctor is not redeclared ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17819](nestjs/nest#17819) fix(core): name the module when metadata entries are invalid ([@thekhegay](https://github.com/thekhegay)) - `microservices` - [#17828](nestjs/nest#17828) fix(microservices): let the redis client retry after a failed connect ([@hktitof](https://github.com/hktitof)) - [#17810](nestjs/nest#17810) fix(microservices): fail every pending request when a callback throws ([@hktitof](https://github.com/hktitof)) ##### Enhancements - `core` - [#17846](nestjs/nest#17846) fix(core): do not skip subsequent middleware after a transient one ([@lehafari](https://github.com/lehafari)) - [#17840](nestjs/nest#17840) fix(core): preserve route handler names ([@Grmiade](https://github.com/Grmiade)) - `common`, `core` - [#17713](nestjs/nest#17713) feat(core): add support for array of global prefixes ([@micalevisk](https://github.com/micalevisk)) - [#17834](nestjs/nest#17834) feat(common,core): add built-in, adapter-agnostic cookies ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - `platform-fastify` - [#17824](nestjs/nest#17824) fix(fastify): honor Nest forceCloseConnections in initHttpServer ([@xia-chao](https://github.com/xia-chao)) - `common` - [#17827](nestjs/nest#17827) fix(common): apply the ParseDatePipe default to every missing value ([@xia-chao](https://github.com/xia-chao)) - `platform-fastify`, `testing` - [#17835](nestjs/nest#17835) feat(fastify): add file upload interceptors backed by [@fastify/multipart](https://github.com/fastify/multipart) ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - `common`, `core`, `platform-fastify` - [#17836](nestjs/nest#17836) feat(common,core,fastify): built-in CSRF protection and security headers ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) ##### Committers: 9 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Alejandro ([@lehafari](https://github.com/lehafari)) - Chris Z ([@haimingZZ](https://github.com/haimingZZ)) - Johnny J. Huirilef Millán ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - Jérémy Fauvel ([@Grmiade](https://github.com/Grmiade)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - Micael Levi L. Cavalcante ([@micalevisk](https://github.com/micalevisk)) - Roman Khegay ([@thekhegay](https://github.com/thekhegay)) - Xia Chao ([@xia-chao](https://github.com/xia-chao)) ## [v12.0.4](https://github.com/nestjs/nest/releases/tag/v12.0.4) ##### v12.0.4 (2026-09-21) ##### Bug fixes - `microservices` - [#17816](nestjs/nest#17816) fix(microservices): let the kafka client retry after a failed connect ([@Xch4rt](https://github.com/Xch4rt)) - [#17786](nestjs/nest#17786) fix(microservices): fail pending rmq requests on client close ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - [#17802](nestjs/nest#17802) fix(microservices): fail pending nats requests on client close ([@hktitof](https://github.com/hktitof)) - [#17803](nestjs/nest#17803) fix(microservices): handle missing grpc package namespace gracefully ([@Se3do](https://github.com/Se3do)) - [#17799](nestjs/nest#17799) fix(microservices): share the processing hook envelope across transports ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17797](nestjs/nest#17797) fix(microservices): close the kafka request-response span exactly once ([@MingLin1995](https://github.com/MingLin1995)) - [#17794](nestjs/nest#17794) fix(microservices): close the request-response span exactly once ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17785](nestjs/nest#17785) fix(microservices): route message handler rejections to handleError ([@hktitof](https://github.com/hktitof)) - `core` - [#17821](nestjs/nest#17821) fix(core): hang on sparse factory inject array ([@xia-chao](https://github.com/xia-chao)) ##### Enhancements - `platform-express` - [#17818](nestjs/nest#17818) Fix: merge multer `limits` key-by-key instead of overriding it wholesale ([@mdrezuanislamridoy](https://github.com/mdrezuanislamridoy)) - `common` - [#17780](nestjs/nest#17780) fix(common): mark parse date pipe options as optional ([@Chy-Zaber-Bin-Zahid](https://github.com/Chy-Zaber-Bin-Zahid)) ##### Dependencies - `common` - [#17793](nestjs/nest#17793) fix(deps): update dependency file-type to v22.1.1 ([@renovate\[bot\]](https://github.com/apps/renovate)) - `platform-fastify` - [#17791](nestjs/nest#17791) fix(deps): update dependency fastify to v5.12.5 ([@renovate\[bot\]](https://github.com/apps/renovate)) ##### Committers: 10 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Chowdhury Zaber Bin Zahid ([@Chy-Zaber-Bin-Zahid](https://github.com/Chy-Zaber-Bin-Zahid)) - Imad - Prakticode ([@prakticode](https://github.com/prakticode)) - Johnny J. Huirilef Millán ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - MD. Ridoy Babu ([@mdrezuanislamridoy](https://github.com/mdrezuanislamridoy)) - Ming ([@MingLin1995](https://github.com/MingLin1995)) - Mohammed Said ([@Se3do](https://github.com/Se3do)) - Pablo Gutiérrez ([@Xch4rt](https://github.com/Xch4rt)) - Xia Chao ([@xia-chao](https://github.com/xia-chao)) ## [v12.0.3](https://github.com/nestjs/nest/releases/tag/v12.0.3) ##### v12.0.3 (2026-09-15) ##### Bug fixes - `microservices` - [#17766](nestjs/nest#17766) fix(microservices): always run the kafka processing end hook ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17757](nestjs/nest#17757) fix(microservices): fail pending requests on client close ([@hktitof](https://github.com/hktitof)) - [#17746](nestjs/nest#17746) fix(microservices): bound memory held for a TCP peer ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17745](nestjs/nest#17745) fix(microservices): destroy open TCP sockets on shutdown ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - `common` - [#17738](nestjs/nest#17738) fix(common): validate uuid version and variant when no version is set ([@otnc](https://github.com/otnc)) - [#17761](nestjs/nest#17761) fix(common): invoke proto-key stripping hook via this in transform ([@koreahghg](https://github.com/koreahghg)) ##### Dependencies - `platform-express` - [#17762](nestjs/nest#17762) fix(deps): update dependency multer to v2.4.0 ([@renovate\[bot\]](https://github.com/apps/renovate)) - `common` - [#17753](nestjs/nest#17753) fix(deps): update dependency file-type to v22.1.0 ([@renovate\[bot\]](https://github.com/apps/renovate)) ##### Committers: 4 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - otoneko. ([@otnc](https://github.com/otnc)) - 한국 ([@koreahghg](https://github.com/koreahghg)) ## [v12.0.2](https://github.com/nestjs/nest/releases/tag/v12.0.2) ##### v12.0.2 (2026-09-14) ##### Bug fixes - `platform-socket.io`, `platform-ws` - [#17666](nestjs/nest#17666) fix(socket.io): keep the message stream alive when a handler throws ([@hktitof](https://github.com/hktitof)) - `microservices` - [#17728](nestjs/nest#17728) fix(microservices): detach signal listeners of connected microservices ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17671](nestjs/nest#17671) fix(microservices): fail requests whose reply subscription is rejected ([@samuelmbabhazi](https://github.com/samuelmbabhazi)) - [#17670](nestjs/nest#17670) fix(microservices): do not treat foreign JSON as an RPC envelope ([@xia-chao](https://github.com/xia-chao)) - [#17644](nestjs/nest#17644) fix(microservices): don't flatten plain handler results with pre-request hooks ([@iamolegga](https://github.com/iamolegga)) - [#17641](nestjs/nest#17641) fix(microservices): run the mqtt listen callback once ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - `common` - [#17710](nestjs/nest#17710) fix(common): collapse duplicate internal slashes in `normalizePath` ([@Asadshah7950](https://github.com/Asadshah7950)) - [#17655](nestjs/nest#17655) fix(common): validate UUID v3 variant ([@gwagjiug](https://github.com/gwagjiug)) - [#17702](nestjs/nest#17702) fix(common): treat empty string as array input in ParseArrayPipe ([@xia-chao](https://github.com/xia-chao)) - `core` - [#17667](nestjs/nest#17667) fix(core): discover factory providers with discovery decorators ([@hktitof](https://github.com/hktitof)) - [#17709](nestjs/nest#17709) fix(core): avoid treating error instances with `statusCode` as http errors ([@Asadshah7950](https://github.com/Asadshah7950)) - [#17625](nestjs/nest#17625) fix(core): clean up repeated shutdown signal listeners ([@Raj4478](https://github.com/Raj4478)) - `platform-fastify` - [#17705](nestjs/nest#17705) fix(fastify): derive neutral version when accept header is absent ([@Gaurav1112](https://github.com/Gaurav1112)) - [#17699](nestjs/nest#17699) fix(fastify): send responses for exceptions thrown from middleware ([@micalevisk](https://github.com/micalevisk)) ##### Enhancements - `microservices` - [#17734](nestjs/nest#17734) feat(microservices): add maxConnectionAttempts to ServerMqtt ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) ##### Dependencies - `platform-fastify` - [#17729](nestjs/nest#17729) fix(deps): update dependency fastify to v5.12.4 ([@renovate\[bot\]](https://github.com/apps/renovate)) ##### Committers: 16 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Alexey Solovyov ([@lyohaplotinka](https://github.com/lyohaplotinka)) - Asad Ali Shah ([@Asadshah7950](https://github.com/Asadshah7950)) - Gyeonghun Park ([@Gyeonghun-Park](https://github.com/Gyeonghun-Park)) - Johnny J. Huirilef Millán ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - Kumar Gaurav ([@Gaurav1112](https://github.com/Gaurav1112)) - Micael Levi L. Cavalcante ([@micalevisk](https://github.com/micalevisk)) - Ming ([@MingLin1995](https://github.com/MingLin1995)) - Mohammed Said ([@Se3do](https://github.com/Se3do)) - Rajeshwar Singh ([@Raj4478](https://github.com/Raj4478)) - Xia Chao ([@xia-chao](https://github.com/xia-chao)) - [@iamolegga](https://github.com/iamolegga) - cui fliter ([@cuishuang](https://github.com/cuishuang)) - samuel mbabhazi ([@samuelmbabhazi](https://github.com/samuelmbabhazi)) - 곽지욱 ([@gwagjiug](https://github.com/gwagjiug))
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
ClientKafka#connect()caches the connection attempt ininitializedand only clears it inclose(). When the attempt rejects (broker unreachable at startup, kafkajs gives up after its retries), the rejected promise stays cached, so every laterconnect()call — and therefore everysend()/emit()— fails with the error of the first attempt, even once the broker is reachable again. The client is stuck untilclose()is called explicitly.On top of that, a partially successful attempt leaks: when the consumer connects and joins its group but the producer fails, the consumer is left behind, and a later attempt would create a second one.
The other transports do not have this problem:
ClientNatsresetsconnectionPromisewhencreateClient()rejects,ClientTCPresets it onclose, andClientMqtt/ClientRMQoverwrite it on everyconnectevent of their underlying client. Kafka has no equivalent, because kafkajs does not emit an event the client could react to.What is the new behavior?
When the connection attempt rejects,
connect()clearsinitialized, disconnects whatever the attempt managed to create (consumer, producer) and re-throws the original error. The nextconnect()call starts a fresh attempt instead of replaying the cached rejection.Successful connections are unchanged: they keep being cached and reused exactly as before.
Regression tests cover both the teardown of a partial connection and the retry on the next call. They use the existing mocked kafkajs setup, so no broker is needed.
Does this PR introduce a breaking change?
Other information