Skip to content

Commit 54d2cc1

Browse files
committed
ci: Improve peer logging to help identify race
1 parent 2b922b1 commit 54d2cc1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

peer/conn.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"crypto/rand"
7+
"crypto/sha256"
78
"io"
89
"sync"
910
"time"
@@ -311,15 +312,22 @@ func (c *Conn) negotiate() {
311312
c.pendingCandidatesMutex.Lock()
312313
defer c.pendingCandidatesMutex.Unlock()
313314
for _, pendingCandidate := range c.pendingRemoteCandidates {
314-
c.opts.Logger.Debug(context.Background(), "flushing remote candidate")
315+
hash := sha256.Sum224([]byte(pendingCandidate.Candidate))
316+
c.opts.Logger.Debug(context.Background(), "flushing buffered remote candidate",
317+
slog.F("hash", hash),
318+
slog.F("length", len(pendingCandidate.Candidate)),
319+
)
315320
err := c.rtc.AddICECandidate(pendingCandidate)
316321
if err != nil {
317-
_ = c.CloseWithError(xerrors.Errorf("flush pending candidates: %w", err))
322+
_ = c.CloseWithError(xerrors.Errorf("flush pending remote candidate: %w", err))
318323
return
319324
}
320325
}
326+
c.opts.Logger.Debug(context.Background(), "flushed buffered remote candidates",
327+
slog.F("count", len(c.pendingRemoteCandidates)),
328+
)
321329
c.pendingCandidatesFlushed = true
322-
c.opts.Logger.Debug(context.Background(), "flushed remote candidates")
330+
c.pendingRemoteCandidates = make([]webrtc.ICECandidateInit, 0)
323331
}
324332

325333
// LocalCandidate returns a channel that emits when a local candidate
@@ -332,12 +340,16 @@ func (c *Conn) LocalCandidate() <-chan webrtc.ICECandidateInit {
332340
func (c *Conn) AddRemoteCandidate(i webrtc.ICECandidateInit) error {
333341
c.pendingCandidatesMutex.Lock()
334342
defer c.pendingCandidatesMutex.Unlock()
343+
fields := []slog.Field{
344+
slog.F("hash", sha256.Sum224([]byte(i.Candidate))),
345+
slog.F("length", len(i.Candidate)),
346+
}
335347
if !c.pendingCandidatesFlushed {
336-
c.opts.Logger.Debug(context.Background(), "adding remote candidate to buffer")
348+
c.opts.Logger.Debug(context.Background(), "bufferring remote candidate", fields...)
337349
c.pendingRemoteCandidates = append(c.pendingRemoteCandidates, i)
338350
return nil
339351
}
340-
c.opts.Logger.Debug(context.Background(), "adding remote candidate")
352+
c.opts.Logger.Debug(context.Background(), "adding remote candidate", fields...)
341353
return c.rtc.AddICECandidate(i)
342354
}
343355

0 commit comments

Comments
 (0)