Skip to content

fix(react-client): await pending addTrack to fix track ops race#527

Merged
czerwiukk merged 1 commit into
fishjam-cloud:mainfrom
Critteros:fix/track-manager-addtrack-race
May 6, 2026
Merged

fix(react-client): await pending addTrack to fix track ops race#527
czerwiukk merged 1 commit into
fishjam-cloud:mainfrom
Critteros:fix/track-manager-addtrack-race

Conversation

@Critteros

Copy link
Copy Markdown
Contributor

Description

getCurrentTrackId now awaits the in-flight addTrack promise before
returning, so callers always see the resolved remote track id once the
track is registered.

  • Add connectionPromiseRef storing the active addTrack job
  • Make getCurrentTrackId async and await pending job
  • Update callers (replaceTrack, refreshStreamedTrack,
    toggleMute, toggleDevice) to await the new async signature
  • Await pauseStreaming in toggleDevice

Motivation and Context

startStreaming set currentTrackIdRef.current only after addTrack
resolved. If the user invoked toggleMute, replaceTrack, or
toggleDevice during that window, getCurrentTrackId returned null
and the operation silently no-op'd (mute toggles ignored, replace
skipped). Awaiting the pending promise removes the race.

Documentation impact

  • Documentation update required
  • Documentation updated in another PR
  • No documentation update required

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)

@czerwiukk czerwiukk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase and check if the tests pass, code itself looks good

@Critteros Critteros force-pushed the fix/track-manager-addtrack-race branch from 4c2c04b to f37828b Compare May 6, 2026 12:27
@czerwiukk czerwiukk merged commit 04a3f39 into fishjam-cloud:main May 6, 2026
1 of 2 checks passed
@Critteros Critteros deleted the fix/track-manager-addtrack-race branch May 8, 2026 09:28
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