From 131dc2e05ca0ef9e7a4d09a472c383c7f4684220 Mon Sep 17 00:00:00 2001 From: sukun Date: Sat, 23 Sep 2023 19:05:40 +0530 Subject: [PATCH] Fix DataChannel.handleOpen Take copy of bufferedAmountLowThreshold and onBufferedAmountLow. This allows us to this later without holding the lock. --- datachannel.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/datachannel.go b/datachannel.go index 1d6d4763930..96ae9121f48 100644 --- a/datachannel.go +++ b/datachannel.go @@ -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) @@ -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() {