fix: serialize Azure TTS backend client lifetimes - #10101
Open
xiongyuyang wants to merge 1 commit into
Open
xiongyuyang wants to merge 1 commit into
xiongyuyang wants to merge 1 commit into
Conversation
kilisamemarisaaa
approved these changes
Sep 16, 2026
kilisamemarisaaa
left a comment
There was a problem hiding this comment.
Reviewed at head 134663a. The provider-instance asyncio lock covers the entire mutable backend context lifetime, so overlapping calls cannot replace or close each other's native Azure/OTTS clients; separate provider instances remain independent. Exact-head Windows/Python 3.12 test run passed 6 cases across native/OTTS success, error, and cancellation paths (4 existing warnings); Ruff passed. Tests drive the public get_audio entry point and verify distinct clients are closed after each outcome. No lifecycle or cleanup blocker found.
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.
Modifications
AzureTTSProvider shares one backend object across requests. Both AzureNativeProvider and OTTSProvider assign
_clienton context entry and close/reset it on exit. Overlapping get_audio calls can therefore overwrite each other's clients: one request closes the other's client and the original client is leaked.Add a provider-instance asyncio lock around the complete backend context lifetime. This preserves the existing token/time caches and closes the client before another synthesis enters. Requests using the same provider now queue; separate provider instances remain independent.
Screenshots or Test Results
python -m pytest tests/unit/test_azure_tts_concurrency.py -q -p no:cacheproviderBefore the fix: all 6 regression cases failed (missing client on successful synthesis or unclosed client after failure/cancellation).
After the fix: 6 passed, 1 existing audioop deprecation warning on Windows/Python 3.12.
Tests drive the public AzureTTSProvider.get_audio entry point and real HTTP client contexts for native Azure and OTTS. Only synthesis execution is mocked to control overlapping calls, errors and cancellation. No external API was called. Ruff check and commit hooks passed.
Checklist
Summary by Sourcery
Serialize synthesis lifetimes for each Azure TTS provider instance to preserve backend client isolation and cleanup under concurrent requests.
Bug Fixes:
Tests: