mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Fix data race in queuepacketconn_test.go
Use mutex when checking the length of a TranscriptPacketConn.
This commit is contained in:
parent
24c42dff13
commit
b9e7865c50
1 changed files with 8 additions and 1 deletions
|
@ -150,6 +150,13 @@ func (c *TranscriptPacketConn) WriteTo(p []byte, addr net.Addr) (int, error) {
|
||||||
return c.PacketConn.WriteTo(p, addr)
|
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
|
// Tests that QueuePacketConn.WriteTo is compatible with the way kcp-go uses
|
||||||
// PacketConn, allocating source buffers in a sync.Pool.
|
// 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.
|
// A sleep after the Write makes buffer reuse more likely.
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
if len(transcript.Transcript) == 0 {
|
if transcript.Length() == 0 {
|
||||||
panic("empty transcript")
|
panic("empty transcript")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue