⚡ Bolt: Fix task leakage and optimize qobuz secret resolution#62
Draft
davidjuarezdev wants to merge 1 commit intomainfrom
Draft
⚡ Bolt: Fix task leakage and optimize qobuz secret resolution#62davidjuarezdev wants to merge 1 commit intomainfrom
davidjuarezdev wants to merge 1 commit intomainfrom
Conversation
Refactored `_get_valid_secret` in `streamrip/client/qobuz.py` to use `asyncio.as_completed` instead of `asyncio.gather`. This optimization immediately yields the first successful secret without waiting for all tasks to complete, significantly reducing slow-tail latency and wasted network I/O. Background tasks are properly cancelled via a `finally` block to prevent resource leakage. Co-authored-by: davidjuarezdev <230496599+davidjuarezdev@users.noreply.github.com>
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.
💡 What: Refactored
_get_valid_secretinstreamrip/client/qobuz.pyto useasyncio.as_completedwith explicit task cancellation instead ofasyncio.gather.🎯 Why: The Qobuz client tests multiple potential API secrets during authentication. Previously, it waited for all secrets to be tested before proceeding, causing slow-tail latency if one of the endpoints hung. This change allows the application to short-circuit and proceed immediately upon finding the first valid secret, while cancelling the remaining pending tasks to prevent background resource leaks.
📊 Impact: Reduces network I/O and speeds up Qobuz authentication by eliminating the wait time for the slowest failing secret request. Resolves a potential memory leak of unawaited/uncancelled background tasks.
🔬 Measurement: Review the network logs during Qobuz authentication; the client will now proceed as soon as the first HTTP 200/401 response is received, and background requests will be visibly cancelled. Verified via passing test suite (
PYTHONPATH=. poetry run pytest tests).PR created automatically by Jules for task 3232499352274167618 started by @davidjuarezdev