From b9e7865c503bfa04a0ef329778a74182c5ae942d Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Tue, 26 Aug 2025 13:15:36 -0400 Subject: [PATCH] Fix data race in queuepacketconn_test.go Use mutex when checking the length of a TranscriptPacketConn. --- common/turbotunnel/queuepacketconn_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/turbotunnel/queuepacketconn_test.go b/common/turbotunnel/queuepacketconn_test.go index 30e69e3..3b4c848 100644 --- a/common/turbotunnel/queuepacketconn_test.go +++ b/common/turbotunnel/queuepacketconn_test.go @@ -150,6 +150,13 @@ func (c *TranscriptPacketConn) WriteTo(p []byte, addr net.Addr) (int, error) { return c.PacketConn.WriteTo(p, addr) } +func (c *TranscriptPacketConn) Length() int { + c.lock.Lock() + defer c.lock.Unlock() + + return len(c.Transcript) +} + // Tests that QueuePacketConn.WriteTo is compatible with the way kcp-go uses // PacketConn, allocating source buffers in a sync.Pool. // @@ -216,7 +223,7 @@ func TestQueuePacketConnWriteToKCP(t *testing.T) { // A sleep after the Write makes buffer reuse more likely. time.Sleep(100 * time.Millisecond) - if len(transcript.Transcript) == 0 { + if transcript.Length() == 0 { panic("empty transcript") }