Do not call state_change_callback with lock #1775
Merged
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.
Building on #1768 , this PR addresses concurrency issues that may be caused by the BrokerConnection state_change_callback, specifically the callback used by KafkaClient to track connecting nodes and the global socket selector.
To that end, I removed the DISCONNECTING connection state, which should simplify the state model a bit. DISCONNECTING was primarily used to hack around the fact that removing a socket from the client selector must be done before the socket is closed. With this change we'll simply keep the socket open until after the DISCONNECTED callback is completed. But in order to avoid other race conditions, we need to clear the conn._sock attribute before we release the lock. And because the current KafkaClient callback assumes that the socket it needs is conn._sock, I went ahead and changed the callback signature to explicitly pass the interesting pieces of data (node_id, socket, connection).
This change is