Repository navigation
fix(client): only deregister the broker registered under that ID - #3752
Merged
Merged
Conversation
deregisterBroker removed whichever broker was registered under the failed broker's ID. If a metadata refresh had replaced that broker in the meantime (its address changed, or it was dropped after a socket error and registered again), a caller still holding the old instance removed the new one instead. The new broker was then never closed and the client lost track of it. Only remove the broker if it is the instance that is registered. An instance that is no longer registered falls through to the seed broker check as before, which also compares by pointer, so it is left alone. Fixes IBM#3145 Signed-off-by: phatlc <[email protected]>
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.
deregisterBrokerlooks the broker up by ID only, so it can remove a different broker from the one it was given.Every caller gets a broker from
LeastLoadedBroker(), drops the client lock, sends a request, and on failure closes that broker and callsderegisterBroker(broker). In the meantime a metadata refresh or coordinator lookup can register a new*Brokerunder the same ID, for example:updateBrokerorregisterBrokerreplaces it because its address changed. The old instance is closed.checkBrokersHealthdrops it after a socket error, andupdateBrokerregisters the instance from the response in its place.The caller's request fails because the old instance is closed or its socket is gone. Its
deregisterBroker(old)then finds the ID in the map and deletes the new broker. That broker is never closed (CloseandRefreshBrokersonly close what is in the map), and the client has lost a live broker until the next refresh registers another one. This matches the leaks under unstable networks that the issue describes.As suggested in the issue,
deregisterBrokernow removes the entry only whenclient.brokers[broker.ID()] == broker.On whether a stale broker should fall through to the seed broker handling: it does, and nothing happens there. Seed brokers are only created by
NewBrokerinrandomizeSeedBrokers(ID -1), and the brokers map only holds brokers decoded from Metadata and FindCoordinator responses. The two sets never share an instance, and the seed branch already comparesbroker == client.seedBrokers[0]by pointer, so a stale registered broker never matches it. Falling through leaves the rest of the function as it was.TestDeregisterBrokerreplaces a broker throughupdateBroker, deregisters the old instance, and checks that the new one is still registered and the seed list is unchanged. It then checks that deregistering the registered instance still removes it. On main the first assertion fails because the map entry is gone.Fixes #3145