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

Fix connection leaks in dependencies by monkey patching gevent queues #656

Merged
merged 2 commits into from
Mar 30, 2022

Conversation

RoganMurley
Copy link
Collaborator

Connection pools implemented using standard library queues can leak connections when a gevent timeout exception is raised. To avoid this gevent queues should be used rather than standard library queues.

We fixed this in baseplate.py Thrift pools, but there are still many such issues in dependencies. In some cases we can explicitly use a gevent queue, but in other cases we have to monkey patch.

Previously we did not monkey patch because it is unclear why gevent patch_queue and patch_all does not patch by default. I've raised an issue asking the gevent team about this, and also started canarying such a change in a Reddit service that was experiencing Kombu connection leaks. The service hasn't experienced any issues with the change so I'd like to merge it upstream.

@@ -24,7 +25,6 @@
from typing import Optional
from typing import TYPE_CHECKING

from gevent import queue as gevent_queue
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Undoing explicitly using a gevent queue, because the standard library queue should be patched.

#643

@@ -0,0 +1,13 @@
from gevent.monkey import patch_module
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Was unsure where to put this file.

Copy link

@MelissaCole MelissaCole left a comment

Choose a reason for hiding this comment

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

lgtm!

@MelissaCole MelissaCole merged commit 578521f into reddit:develop Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants