Skip to content

Commit

Permalink
Fix DataChannel.handleOpen
Browse files Browse the repository at this point in the history
Take copy of bufferedAmountLowThreshold and onBufferedAmountLow.
This allows us to this later without holding the lock.
  • Loading branch information
sukunrt authored and Sean-Der committed Sep 24, 2023
1 parent c785f25 commit 48303e5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions datachannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ func (d *DataChannel) onMessage(msg DataChannelMessage) {
func (d *DataChannel) handleOpen(dc *datachannel.DataChannel, isRemote, isAlreadyNegotiated bool) {
d.mu.Lock()
d.dataChannel = dc
bufferedAmountLowThreshold := d.bufferedAmountLowThreshold
onBufferedAmountLow := d.onBufferedAmountLow
d.mu.Unlock()
d.setReadyState(DataChannelStateOpen)

Expand All @@ -312,8 +314,8 @@ func (d *DataChannel) handleOpen(dc *datachannel.DataChannel, isRemote, isAlread
// * already negotiated datachannels should fire OnOpened
if d.api.settingEngine.detach.DataChannels || isRemote || isAlreadyNegotiated {
// bufferedAmountLowThreshold and onBufferedAmountLow might be set earlier
d.dataChannel.SetBufferedAmountLowThreshold(d.bufferedAmountLowThreshold)
d.dataChannel.OnBufferedAmountLow(d.onBufferedAmountLow)
d.dataChannel.SetBufferedAmountLowThreshold(bufferedAmountLowThreshold)
d.dataChannel.OnBufferedAmountLow(onBufferedAmountLow)
d.onOpen()
} else {
dc.OnOpen(func() {
Expand Down

0 comments on commit 48303e5

Please sign in to comment.