Skip to content

harden against resource setup/cleanup race conditions #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 21, 2025

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.

Copy link

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, francamps, chrismanahan, zachkrall, vpicone, twitchard, garrettbo and KarolinaCharlinska 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