Fix rate limit callback waits and support the predicate cache on trio - #160
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #160 +/- ##
==========================================
+ Coverage 95.89% 96.25% +0.35%
==========================================
Files 7 7
Lines 1097 1122 +25
Branches 126 123 -3
==========================================
+ Hits 1052 1080 +28
+ Misses 26 25 -1
+ Partials 19 17 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add a RunBlocking event so the generator can defer blocking calls to the caller. The sync client invokes them directly; the async client runs them via anyio.to_thread, keeping cache reads, writes, and mkdir off the event loop.
Replace @attr.s(slots=True) with @attrs.define and typed attributes.
The only locks these events carry are filelock.FileLock instances for the predicate cache, and the async handler's acquire loop is specific to filelock's non-blocking behaviour (raising Timeout). Name them accordingly so future lock types get their own events instead of overloading these.
RazerM
force-pushed
the
feature/ratelimit-callback-wait
branch
3 times, most recently
from
August 23, 2026 12:50
2abf460 to
62e0668
Compare
The async ReleaseFileLock handler's unshielded to_thread.run_sync raised Cancelled at its entry checkpoint before lock.release() ran, so a cancel scope firing while the predicate cache FileLock was held leaked the lock until garbage collection, deadlocking other tasks and processes. Shield the release, and shield each non-blocking acquire attempt so a cancellation cannot discard a successful acquire either.
The documentation shows a plain function callback for both clients, but AsyncSpaceTrackClient unconditionally awaited the callback's return value, so a non-coroutine callback raised TypeError inside the rate limit task group and aborted the in-flight request. Only await the result when it is awaitable.
A callback exception was raised in the daemon thread and silently discarded by the default threading excepthook, so the request proceeded as if nothing happened, while the async client propagates the same exception and aborts the request. Capture the callback outcome in the thread and unwrap it after the join so both clients behave the same.
RazerM
force-pushed
the
feature/ratelimit-callback-wait
branch
from
August 23, 2026 12:51
62e0668 to
8f59dd7
Compare
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.
Rate limit waits now wait for the callback to finish in all clients, and an exception raised by the callback propagates instead of being silently discarded, including in the sync client. The async client accepts a plain function as the callback, as the documentation shows.
The predicate cache now works on trio, with cache file I/O running in a worker thread, and the cache file lock is released correctly when a request is cancelled.
The event classes are modernised to
attrs.define, and the file lock events are named explicitly.