Skip to content

Commit 7327507

Browse files
committed
Fix race in peer logging
1 parent 1e62837 commit 7327507

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

peer/conn.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ func (c *Conn) init() error {
143143
}
144144
})
145145
c.rtc.OnConnectionStateChange(func(pcs webrtc.PeerConnectionState) {
146-
if c.isClosed() {
147-
return
148-
}
146+
// Close must be locked here otherwise log output can appear
147+
// after the connection has been closed.
148+
c.closeMutex.Lock()
149+
defer c.closeMutex.Unlock()
149150

150151
c.opts.Logger.Debug(context.Background(), "rtc connection updated",
151152
slog.F("state", pcs),

0 commit comments

Comments
 (0)