⚡ Bolt: Use as_completed for early exit in Qobuz app secret check#55
Draft
davidjuarezdev wants to merge 1 commit intomainfrom
Draft
⚡ Bolt: Use as_completed for early exit in Qobuz app secret check#55davidjuarezdev wants to merge 1 commit intomainfrom
davidjuarezdev wants to merge 1 commit intomainfrom
Conversation
Replaces `asyncio.gather` with `asyncio.as_completed` in `_get_valid_secret` to short-circuit as soon as a valid secret is found. Pending tasks are cancelled in a `finally` block to prevent background task leakage and unnecessary network requests. 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: Replaced
asyncio.gatherwithasyncio.as_completedand task cancellation in the Qobuz_get_valid_secretmethod.🎯 Why: Previously, the application would test all app secrets concurrently but wait for all requests to complete (or fail/timeout) before returning the first valid one. This caused "slow-tail latency" where the application's startup time was dictated by the slowest failing network request, even if a working secret was found almost instantly. It also leaked background requests, consuming unnecessary network I/O and CPU cycles.
📊 Impact: Application startup time for Qobuz is now only as slow as the fastest successful secret check. Reduces unnecessary network payload and prevents asynchronous task leakage.
🔬 Measurement: This optimization can be verified by mocking multiple secret checks with varying response times. With the optimization, the valid secret is returned as soon as its request completes, and the longer (slower) requests are cancelled rather than blocking the event loop.
PR created automatically by Jules for task 16356414664198470609 started by @davidjuarezdev