Skip to content

⚡ Bolt: Use as_completed for early exit in Qobuz app secret check#55

Draft
davidjuarezdev wants to merge 1 commit intomainfrom
bolt/qobuz-app-secret-early-exit-16356414664198470609
Draft

⚡ Bolt: Use as_completed for early exit in Qobuz app secret check#55
davidjuarezdev wants to merge 1 commit intomainfrom
bolt/qobuz-app-secret-early-exit-16356414664198470609

Conversation

@davidjuarezdev
Copy link
Copy Markdown
Owner

💡 What: Replaced asyncio.gather with asyncio.as_completed and task cancellation in the Qobuz _get_valid_secret method.
🎯 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

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>
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