Skip to content

Commit 82a786c

Browse files
pblazejclaude
andcommitted
fix(transport): remove removeTrack loop before close to prevent crashes
removeTrack nulls sender tracks and changes transceiver directions, causing PeerConnection::Close() to skip ClearSend/DetachTrack in its StopTransceiverProcedure and hit edge cases in the worker-thread teardown (ICE use-after-free, AVAudioEngine deallocation assertion). Close() handles full cleanup on its own. The loop was originally commented out as "not required?" and was accidentally uncommented during a threading refactor (101e09d). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 40f637c commit 82a786c

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Sources/LiveKit/Core/Transport.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ actor Transport: NSObject, Loggable {
204204

205205
// Stop listening to delegate
206206
_pc.delegate = nil
207-
// Remove all senders (if any)
208-
for sender in _pc.senders {
209-
_pc.removeTrack(sender)
210-
}
211207

208+
// Do not call removeTrack before close — it nulls sender tracks and
209+
// changes transceiver directions, causing Close() to skip ClearSend/
210+
// DetachTrack in its StopTransceiverProcedure and hit edge cases in
211+
// the worker-thread teardown (ICE use-after-free, AVAudioEngine
212+
// deallocation assertion). Close() handles full cleanup on its own.
212213
_pc.close()
213214
}
214215
}

0 commit comments

Comments
 (0)