-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ENH] Connection pool FD leak v2 #2014
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
Needs a test for to verify the file descriptor are being closed. Tests might be flaky due to weakrefs relying on GC. |
3a969a8
to
2615912
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a screenshot showing the FD count going down?
@HammadB here's a short video to demo the PR: https://www.loom.com/share/0d5fe43c9183439f9261381651b35ec5?sid=8fd8330f-6db9-4b5d-be23-637888314d5a |
May I ask when it will close |
2615912
to
27b8594
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you know why this was happening? If I'm understanding correctly this makes it more likely for connections to be GCed but may not fix the underlying bug
it seems like this may result in a new connection being created for each transaction?
just want to understand more how this works since I ran into a similar issue a few months ago and never fully tracked it down
The root of the issue is that thread locals which we use for tracking connections do not work (think: deterministically) well with async contexts, which FastAPI uses under the hood. This is what https://peps.python.org/pep-0567/ attempts to solve with contextvars. The PerThreadConnection pool leaks connections as the thread locals get recycled by asyncio (occasionally). However, we keep references to the connection in the I had a prior impl with contextvars, but that introduces challenges of its own - the contextvars should ideally be defined at the top of the call stack in FastAPI (this is what |
I see, thank you for the great explanation. :) |
a804043
to
0149135
Compare
0149135
to
1c0c615
Compare
Closes #1379
Description of changes
Summarize the changes made by this PR.
connections
set.Test plan
How are these changes tested?
pytest
for python,yarn test
for jsDocumentation Changes
N/A
Refs