add preconnect audio buffer API to LocalAudioTrack#648
add preconnect audio buffer API to LocalAudioTrack#648theomonnom wants to merge 7 commits intomainfrom
Conversation
Adds start_preconnect_buffer/stop_preconnect_buffer/send_preconnect_buffer to LocalAudioTrack, backed by a zero-allocation circular bytearray ring buffer. Sends buffered audio via byte stream data channels using the existing lk.agent.pre-connect-audio-buffer protocol.
| if self._preconnect_buffer is None: | ||
| raise RuntimeError("preconnect buffer is not active") | ||
|
|
||
| async with self._send_lock: | ||
| data = self._preconnect_buffer.capture() |
There was a problem hiding this comment.
🟡 TOCTOU race: _preconnect_buffer checked before lock but accessed inside lock
In send_preconnect_buffer, self._preconnect_buffer is checked for None at line 121 before acquiring self._send_lock at line 124. If the lock is contended (another send_preconnect_buffer call is in-flight), the async with self._send_lock: line yields control. During this yield, stop_preconnect_buffer() (which is synchronous) can be called from another callback—setting self._preconnect_buffer = None at livekit-rtc/livekit/rtc/track.py:116. When the lock is finally acquired, self._preconnect_buffer.capture() at line 125 will raise AttributeError: 'NoneType' object has no attribute 'capture'. The fix is to move the None-check inside the lock.
| if self._preconnect_buffer is None: | |
| raise RuntimeError("preconnect buffer is not active") | |
| async with self._send_lock: | |
| data = self._preconnect_buffer.capture() | |
| async with self._send_lock: | |
| if self._preconnect_buffer is None: | |
| raise RuntimeError("preconnect buffer is not active") | |
| data = self._preconnect_buffer.capture() |
Was this helpful? React with 👍 or 👎 to provide feedback.
No description provided.