Fix race conditions in HostConnection that happen during shutdown#112
Merged
dkropachev merged 4 commits intoscylladb:masterfrom Oct 18, 2021
Merged
Fix race conditions in HostConnection that happen during shutdown#112dkropachev merged 4 commits intoscylladb:masterfrom
dkropachev merged 4 commits intoscylladb:masterfrom
Conversation
Author
|
This PR should fix #111, here's the full log of the problem: You can see the "Shutting down connections to %s" line from Forgot to mention in the commit message, this problem appears when cluster connection opens and closes very quickly - as it happened in this case. |
d87a031 to
4beb587
Compare
bentsi
reviewed
Oct 18, 2021
Author
|
Made a quick repro, fails on master almost every time: https://gist.github.com/6d0065db359fe8a5134851265d9b559e Log: |
4beb587 to
c292c8f
Compare
28350f3 to
1af8860
Compare
1af8860 to
c816036
Compare
c816036 to
7e38091
Compare
Collaborator
|
@k0machi, please add lock to the following routines: |
dkropachev
requested changes
Oct 18, 2021
dkropachev
approved these changes
Oct 18, 2021
a2147a8 to
ed0bcab
Compare
ed0bcab to
7766c0e
Compare
Previously, locking used in HostConnection would just check if was shutdown or to set the is_shutdown attribute. This leads to a problem where Thread A acquires lock, checks the flag, releases lock, checks branch condition for opening a new shard connection, gets scheduled away, while Thread B starts shutdown - acquires lock, sets flag, releases lock, starts closing connections and gets scheduled away - leading to a race where once Thread A resumes, it grows the dictionary being viewed by Thread B with a new connection - even though it should not do so anymore. This commit addresses this by moving any operation on the _connections under a lock
7766c0e to
7f2cae3
Compare
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.
Previously, locking used in HostConnection would just check if was
shutdown or to set the is_shutdown attribute. This leads to a problem
where Thread A acquires lock, checks the flag, releases lock, checks
branch condition for opening a new shard connection, gets scheduled away,
while Thread B starts shutdown - acquires lock, sets flag, releases lock, starts
closing connections and gets scheduled away - leading to a race where once
Thread A resumes, it grows the dictionary being viewed by Thread B with a new
connection - even though it should not do so anymore. This commit
addresses this by moving any operation on the _connections under a lock
Also, this commit adds an internal list to track scheduled futures for the thread executor - preventing shard connections from proceeding if connection pool was shut down
Fixes #111
Trello