Skip to content

Do not call state_change_callback with lock #1775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 3, 2019
Merged

Do not call state_change_callback with lock #1775

merged 4 commits into from
Apr 3, 2019

Conversation

dpkp
Copy link
Owner

@dpkp dpkp commented Apr 2, 2019

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 Reviewable

Copy link
Contributor

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I see looks good, but I don't have a deep understanding of this section of the code.

@tvoinarovskyi do you have time to take a look as well?

dpkp added 3 commits April 2, 2019 09:29
  * Remove DISCONNECTING connection state
  * do not call state_change_callback with lock
  * Pass node_id, socket, and connection object to callback
@dpkp dpkp force-pushed the conn_state_change branch from 02fadd3 to 0045c61 Compare April 2, 2019 16:30
@dpkp dpkp changed the base branch from kafka_conn_locking_too to master April 2, 2019 16:30
@dpkp dpkp force-pushed the conn_state_change branch from 0045c61 to 809f35f Compare April 2, 2019 16:31
@dpkp dpkp merged commit 91d3149 into master Apr 3, 2019
@dpkp dpkp deleted the conn_state_change branch April 3, 2019 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants