Skip to content

Commit eaacbca

Browse files
committed
fix: Potential deadlock in peer.Channel dc.OnOpen
1 parent 62e6856 commit eaacbca

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

peer/channel.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,16 @@ func (c *Channel) init() {
122122
})
123123
c.dc.OnOpen(func() {
124124
c.closeMutex.Lock()
125-
defer c.closeMutex.Unlock()
126-
127125
c.conn.logger().Debug(context.Background(), "datachannel opening", slog.F("id", c.dc.ID()), slog.F("label", c.dc.Label()))
128126
var err error
129127
c.rwc, err = c.dc.Detach()
130128
if err != nil {
129+
c.closeMutex.Unlock()
131130
_ = c.closeWithError(xerrors.Errorf("detach: %w", err))
132131
return
133132
}
133+
c.closeMutex.Unlock()
134+
134135
// pion/webrtc will return an io.ErrShortBuffer when a read
135136
// is triggerred with a buffer size less than the chunks written.
136137
//

0 commit comments

Comments
 (0)