Skip to content
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

better thread-safety for ConnectionPool #1270

Merged
merged 7 commits into from
Jan 30, 2020
Merged

Conversation

andymccurdy
Copy link
Contributor

@andymccurdy andymccurdy commented Jan 27, 2020

This PR implements better thread safety for ConnectionPool.

Fixes #1138
Fixes #1178
Fixes #906
Fixes #1262

'AuthenticationError', 'BusyLoadingError', 'ConnectionError', 'DataError',
'InvalidResponse', 'PubSubError', 'ReadOnlyError', 'RedisError',
'ResponseError', 'TimeoutError', 'WatchError'
'Redis',
Copy link

Choose a reason for hiding this comment

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

If listing these on line by line, consider sorting them by name to make it easier to find when looking through the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree.

@@ -1085,49 +1095,96 @@ def __eq__(self, other):

def reset(self):
self.pid = os.getpid()
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently, this code still exhibits the race condition described in #1138 (comment) and addressed in PR #1262.

The PR does not change the behavior (w.r.t. issue #1138) for me. Moving this line to the end of the method does help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmbnomis Do you have a brief code sample that can repro what you're seeing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, there are at least three layers of modules between my failing tests and redis-py.

But, based on my assumption what goes wrong, I cobbled together gmbnomis@23a9c46. Notice how the assertion in gmbnomis@23a9c46#diff-81266569122b74f1e11f8a1cd3b12d24R115 suddenly fails, as it reuses old data from the parent process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what's going on now. You're right, setting the PID should happen as the very last call as the PID check isn't protected via a lock for performance reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmbnomis I pushed the change to this PR. Would you mind testing this branch in your setup and see if it fixes your issue? I'd like to get this out in the next release.

Copy link
Contributor

Choose a reason for hiding this comment

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

@andymccurdy I gave it a spin and I can't reproduce the problem anymore. Thank you for fixing the issue!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent! Thanks for helping to figure out what was happening and the testing effort! I'm going to merge this and release redis-py 3.4.0 now.

@codecov-io
Copy link

codecov-io commented Jan 30, 2020

Codecov Report

Merging #1270 into master will decrease coverage by 1.42%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1270      +/-   ##
==========================================
- Coverage   92.67%   91.24%   -1.43%     
==========================================
  Files          20       20              
  Lines        6426     6273     -153     
==========================================
- Hits         5955     5724     -231     
- Misses        471      549      +78
Impacted Files Coverage Δ
redis/__init__.py 83.33% <ø> (ø) ⬆️
tests/test_multiprocessing.py 77.89% <ø> (-0.9%) ⬇️
redis/exceptions.py 100% <100%> (ø) ⬆️
redis/connection.py 81.14% <58.13%> (-0.96%) ⬇️
redis/_compat.py 32.25% <0%> (-54.95%) ⬇️
redis/utils.py 66.66% <0%> (-2.09%) ⬇️
tests/test_encoding.py 95.83% <0%> (-0.17%) ⬇️
redis/client.py 85.67% <0%> (-0.08%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09a17ea...013c963. Read the comment docs.

@andymccurdy andymccurdy merged commit 4287963 into master Jan 30, 2020
gmbnomis added a commit to gmbnomis/pulpcore that referenced this pull request Jan 31, 2020
gmbnomis added a commit to gmbnomis/pulpcore that referenced this pull request Jan 31, 2020
@chayim chayim deleted the threadsafe-pools branch October 17, 2021 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants