Skip to content

harden against resource setup/cleanup race conditions#343

Merged
yinishi merged 8 commits intomainfrom
yini/disconnecting-race-condition
May 21, 2025
Merged

harden against resource setup/cleanup race conditions#343
yinishi merged 8 commits intomainfrom
yini/disconnecting-race-condition

Conversation

@yinishi
Copy link
Contributor

@yinishi yinishi commented May 21, 2025

PR includes a handful of changes to harden against various potential race conditions.

  • Ensures each resource setup/teardown step is awaited before moving onto the next resource, instead of setting up resources in parallel. (parallelism is not possible as explained in the next bullet point)
  • Updates the order in which audio player, socket, and microphone are connected and disconnected - this ensures that dependencies are always initialized first, e.g. audio player should be set up before the socket connects, socket should be connected before microphone starts sending audio. Reverse order for teardown.
  • Adds guards to make sure that the audio player is connected before the socket tries to send it any audio data to the audio player.
  • Adds guards to makes sure the socket is connected before the user tries to send any messages to the assistant backend.
  • Adds guards to interrupt the connect function to prevent initializing a resource if the connection attempt was canceled. This prevents race conditions like the following scenario: the user could call connect, then call disconnect before the audio player was set up, but the original connect call continues to set up the audio player.
  • Add retries to the audio player and microphone stop functions.

@vercel
Copy link
Contributor

vercel bot commented May 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
empathic-voice-api-js-next-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 6:42pm

@yinishi yinishi marked this pull request as ready for review May 21, 2025 18:13
@yinishi yinishi requested review from a team, KarolinaCharlinska, chrismanahan, francamps, garrettbo, twitchard, vpicone and zachkrall and removed request for a team May 21, 2025 18:13
@yinishi yinishi merged commit f9dd3f5 into main May 21, 2025
3 checks passed
@yinishi yinishi deleted the yini/disconnecting-race-condition branch May 21, 2025 18:43
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.

2 participants