Fixed an issue in BaseOutputTransport where the loop could consume all CPU.

This commit is contained in:
Filipi Fuchter
2025-08-06 12:42:58 -03:00
parent 4364990fd0
commit bbe01d10ef
2 changed files with 11 additions and 0 deletions

View File

@@ -81,6 +81,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed an issue in the `BaseOutputTransport`, mainly reproducible with
`FastAPIWebsocketOutputTransport` when the audio mixer was enabled, where the
loop could consume 100% CPU by continuously returning without delay, preventing
other asyncio tasks (such as cancellation or shutdown signals) from being
processed.
- Fixed an issue where `BotStartedSpeakingFrame` and `BotStoppedSpeakingFrame`
were not emitted when using `TavusVideoService` or `HeyGenVideoService`.

View File

@@ -658,6 +658,11 @@ class BaseOutputTransport(FrameProcessor):
num_channels=self._params.audio_out_channels,
)
yield frame
# Allow other asyncio tasks to execute by adding a small sleep
# Without this sleep, in task cancellation scenarios, this loop would
# continuously return without any delay, leading to 100% CPU utilization
# and preventing cancel/stop signals from being processed properly
await asyncio.sleep(0)
if self._mixer:
return with_mixer(BOT_VAD_STOP_SECS)