Last active
November 5, 2021 17:25
-
-
Save Sean-Der/5f37e64bacd6a7dd6ba9df5faeff3f2e to your computer and use it in GitHub Desktop.
DataChannel race
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/peerconnection.go b/peerconnection.go | |
index a5d50ee..5dbf46e 100644 | |
--- a/peerconnection.go | |
+++ b/peerconnection.go | |
@@ -1313,28 +1313,6 @@ func (pc *PeerConnection) startSCTP() { | |
return | |
} | |
- | |
- // DataChannels that need to be opened now that SCTP is available | |
- // make a copy we may have incoming DataChannels mutating this while we open | |
- pc.sctpTransport.lock.RLock() | |
- dataChannels := append([]*DataChannel{}, pc.sctpTransport.dataChannels...) | |
- pc.sctpTransport.lock.RUnlock() | |
- | |
- var openedDCCount uint32 | |
- for _, d := range dataChannels { | |
- if d.ReadyState() == DataChannelStateConnecting { | |
- err := d.open(pc.sctpTransport) | |
- if err != nil { | |
- pc.log.Warnf("failed to open data channel: %s", err) | |
- continue | |
- } | |
- openedDCCount++ | |
- } | |
- } | |
- | |
- pc.sctpTransport.lock.Lock() | |
- pc.sctpTransport.dataChannelsOpened += openedDCCount | |
- pc.sctpTransport.lock.Unlock() | |
} | |
func (pc *PeerConnection) handleUndeclaredSSRC(ssrc SSRC, remoteDescription *SessionDescription) (handled bool, err error) { | |
diff --git a/sctptransport.go b/sctptransport.go | |
index 41c635b..ef4b746 100644 | |
--- a/sctptransport.go | |
+++ b/sctptransport.go | |
@@ -115,6 +115,28 @@ func (r *SCTPTransport) Start(remoteCaps SCTPCapabilities) error { | |
r.sctpAssociation = sctpAssociation | |
r.state = SCTPTransportStateConnected | |
+ // DataChannels that need to be opened now that SCTP is available | |
+ // make a copy we may have incoming DataChannels mutating this while we open | |
+ r.lock.RLock() | |
+ dataChannels := append([]*DataChannel{}, r.dataChannels...) | |
+ r.lock.RUnlock() | |
+ | |
+ var openedDCCount uint32 | |
+ for _, d := range dataChannels { | |
+ if d.ReadyState() == DataChannelStateConnecting { | |
+ err := d.open(r) | |
+ if err != nil { | |
+ r.log.Warnf("failed to open data channel: %s", err) | |
+ continue | |
+ } | |
+ openedDCCount++ | |
+ } | |
+ } | |
+ | |
+ r.lock.Lock() | |
+ r.dataChannelsOpened += openedDCCount | |
+ r.lock.Unlock() | |
+ | |
go r.acceptDataChannels(sctpAssociation) | |
return nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment