-
Notifications
You must be signed in to change notification settings - Fork 123
Change ThreadLock to ThreadRLock to resolve rare deadlock #1003
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
base: master
Are you sure you want to change the base?
Conversation
@tomchristie Is the team aware of this PR? I'd love to get an opinion on this PR because we still see this issue pop up. (#990) |
I tested it, and this pull request doesn't seem to work for #1029 ? |
Could be, the issue we experience is not really related to large files so your problem likely has a different root cause |
I wouldn't make this change without a clear understanding of why a re-entrant lock would be required here. Incidentally: The httpx 1..0 prelease has a simpler stack here. |
We are seeing this issue sporadically as well. Specifically, it seems to occur when an exception is thrown in the middle of http response streaming, and an immediate retry after that. We haven't been able to reproduce it reliably based on these factors alone, unfortunately, but I managed to grab a few thread dumps, and it clearly shows an attempt to acquire a lock from within
|
Summary
This pull request addresses a rare edge case issue causing a thread deadlock with access to
_optional_thread_lock
in ConnectionPool. The solution involves changing ThreadLock to ThreadRLock to allow reentrant locking and resolve the deadlock.We have encountered a rare deadlock issue in our production environment while using HTTP Core in a multithreaded setup. The issue manifests in rare cases as threads indefinitely waiting to acquire a lock, causing the entire worker to hang. This deadlock occurs when the same thread attempts to acquire the lock multiple times without releasing it.
This is important to meet the library's goal of being thread safe.
For more details, please refer to the discussion here.
This issue is also felt by other users of the lib although explained less clearly like in #997.
Checklist