Fix lock not released in _iter_cached causing potential deadlock#1455
Open
bysiber wants to merge 1 commit intodateutil:masterfrom
Open
Fix lock not released in _iter_cached causing potential deadlock#1455bysiber wants to merge 1 commit intodateutil:masterfrom
bysiber wants to merge 1 commit intodateutil:masterfrom
Conversation
The cache lock is acquired at the start of the refill block, but both break paths (cache_complete check and StopIteration handler) exit the while loop without releasing it. Any subsequent call to _iter_cached on the same instance from another thread will deadlock on acquire(). Add release() calls before both break statements.
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.
Summary
rrulebase._iter_cachedcan deadlock because the cache lock is not released on two of the three exit paths from the refill block.Problem
The lock is acquired at the start of the cache refill section, but both
breakpaths exit thewhileloop without callingrelease():Path 1: When
_cache_completeis True (another thread finished caching while we waited for the lock),breakexits without release.Path 2: When
StopIterationis caught (generator exhausted),breakexits without release.Any subsequent thread calling
_iter_cachedon the same instance will hang indefinitely onacquire().Reproduction
Fix
Add
release()before bothbreakstatements to ensure the lock is always released when exiting the refill block.