Skip to content

Commit f655897

Browse files
committed
Improve comment
1 parent f4c9dc2 commit f655897

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

peer/conn.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,22 @@ type Conn struct {
142142
func (c *Conn) init() error {
143143
c.rtc.OnNegotiationNeeded(c.negotiate)
144144
c.rtc.OnICEConnectionStateChange(func(iceConnectionState webrtc.ICEConnectionState) {
145+
// Close must be locked here otherwise log output can appear
146+
// after the connection has been closed.
147+
c.closeMutex.Lock()
148+
defer c.closeMutex.Unlock()
145149
if c.isClosed() {
146150
return
147151
}
148152

149-
c.opts.Logger.Debug(context.Background(), "ice connection updated",
153+
c.opts.Logger.Debug(context.Background(), "ice connection state updated",
150154
slog.F("state", iceConnectionState))
151155
})
152156
c.rtc.OnICEGatheringStateChange(func(iceGatherState webrtc.ICEGathererState) {
157+
// Close can't be locked here, because this is triggered
158+
// when close is called. It doesn't appear this get's
159+
// executed after close though, so it shouldn't cause
160+
// problems.
153161
if c.isClosed() {
154162
return
155163
}

0 commit comments

Comments
 (0)