Skip to content

Commit

Permalink
fix race in datachannel handleOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Sep 23, 2023
1 parent e409a1d commit 49d8208
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 49d8208

Please sign in to comment.