Skip to content

⚡ Bolt: Fix task leakage and optimize qobuz secret resolution#62

Draft
davidjuarezdev wants to merge 1 commit intomainfrom
bolt-qobuz-secret-short-circuiting-3232499352274167618
Draft

⚡ Bolt: Fix task leakage and optimize qobuz secret resolution#62
davidjuarezdev wants to merge 1 commit intomainfrom
bolt-qobuz-secret-short-circuiting-3232499352274167618

Conversation

@davidjuarezdev
Copy link
Copy Markdown
Owner

💡 What: Refactored _get_valid_secret in streamrip/client/qobuz.py to use asyncio.as_completed with explicit task cancellation instead of asyncio.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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant