Repository navigation
fix(microservices): keep a newer kafka connection when a stale one fails - #17869
Merged
Merged
Conversation
A connect() attempt that failed after close() and a new connect() cleared the newer attempt's initialized promise and disconnected its consumer and producer. Only reset the shared state when the failing attempt is still the current one, and have it disconnect just the instances it created itself, as ClientRedis and ClientRMQ already do.
4 of 12 tasks
4 of 12 tasks
Closed
2 tasks done
4 of 12 tasks
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
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
When a
ClientKafka.connect()attempt fails, its.catchhandler setsthis.initialized = nulland callsdiscardPartialConnection(). That clears_consumer,_producerandclientand disconnects whatever they currently point to. It never checks whether the failing attempt is still the current one. So ifclose()and thenconnect()run while attempt #1 is still pending, and #1 fails afterwards, it drops the newer attempt'sinitializedpromise and disconnects the newer consumer and producer.What is the new behavior?
This uses the same guard as
ClientRedisandClientRMQ(#17865):connect()keeps the attempt's promise in a local variable and passes it todiscardPartialConnection(). The shared state (initialized,client,_consumer,_producer) is only reset whilethis.initializedis still that promise.initializeClientAndConnections()now also records the consumer and producer it creates in a per-attempt object. A stale attempt uses it to disconnect only its own instances, even after a newer attempt has replaced them on the client.The new test, "should not discard a newer connection when a stale attempt fails", fails without the fix and passes with it.
Does this PR introduce a breaking change?
Other information
A stale attempt can still overwrite
client,_consumeror_producerif it progresses past anawaitafterclose()+connect(), or even resolves successfully. This PR doesn't cover that;ClientRMQhas the same gap, and it can be handled separately.