Skip to content

Commit 4202736

Browse files
committed
don't reuse conn
1 parent f750307 commit 4202736

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

p2p/transport/quic/conn_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,11 @@ func TestStatelessReset(t *testing.T) {
563563
}
564564
}
565565

566-
func newUPDConnLocalhost(t testing.TB) *net.UDPConn {
566+
func newUDPConnLocalhost(t testing.TB, port int) (*net.UDPConn, func()) {
567567
t.Helper()
568-
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
568+
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: port})
569569
require.NoError(t, err)
570-
t.Cleanup(func() { conn.Close() })
571-
return conn
570+
return conn, func() { conn.Close() }
572571
}
573572

574573
func testStatelessReset(t *testing.T, tc *connTestCase) {
@@ -582,7 +581,7 @@ func testStatelessReset(t *testing.T, tc *connTestCase) {
582581

583582
var drop uint32
584583
dropCallback := func(quicproxy.Direction, []byte) bool { return atomic.LoadUint32(&drop) > 0 }
585-
proxyConn := newUPDConnLocalhost(t)
584+
proxyConn, cleanup := newUDPConnLocalhost(t, 0)
586585
proxy := quicproxy.Proxy{
587586
Conn: proxyConn,
588587
ServerAddr: ln.Addr().(*net.UDPAddr),
@@ -621,7 +620,9 @@ func testStatelessReset(t *testing.T, tc *connTestCase) {
621620
atomic.StoreUint32(&drop, 1)
622621
ln.Close()
623622
(<-connChan).Close()
623+
proxyLocalPort := proxy.LocalAddr().(*net.UDPAddr).Port
624624
proxy.Close()
625+
cleanup()
625626

626627
// Start another listener (on a different port).
627628
ln, err = serverTransport.Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1"))
@@ -630,6 +631,8 @@ func testStatelessReset(t *testing.T, tc *connTestCase) {
630631
// Now that the new server is up, re-enable packet forwarding.
631632
atomic.StoreUint32(&drop, 0)
632633

634+
proxyConn, cleanup = newUDPConnLocalhost(t, proxyLocalPort)
635+
defer cleanup()
633636
// Recreate the proxy, such that its client-facing port stays constant.
634637
proxy = quicproxy.Proxy{
635638
Conn: proxyConn,

p2p/transport/webrtc/transport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ func TestTransportWebRTC_PeerConnectionDTLSFailed(t *testing.T) {
776776
require.Nil(t, conn)
777777
}
778778

779-
func newUPDConnLocalhost(t testing.TB) *net.UDPConn {
779+
func newUDPConnLocalhost(t testing.TB) *net.UDPConn {
780780
t.Helper()
781781
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
782782
require.NoError(t, err)
@@ -797,7 +797,7 @@ func TestConnectionTimeoutOnListener(t *testing.T) {
797797

798798
var drop atomic.Bool
799799
proxy := quicproxy.Proxy{
800-
Conn: newUPDConnLocalhost(t),
800+
Conn: newUDPConnLocalhost(t),
801801
ServerAddr: ln.Addr().(*net.UDPAddr),
802802
DropPacket: func(quicproxy.Direction, []byte) bool { return drop.Load() },
803803
}

p2p/transport/webtransport/transport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ func (s *reportingScope) ReserveMemory(size int, _ uint8) error {
540540
return nil
541541
}
542542

543-
func newUPDConnLocalhost(t testing.TB) *net.UDPConn {
543+
func newUDPConnLocalhost(t testing.TB) *net.UDPConn {
544544
t.Helper()
545545
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
546546
require.NoError(t, err)
@@ -582,7 +582,7 @@ func TestFlowControlWindowIncrease(t *testing.T) {
582582
}()
583583

584584
proxy := quicproxy.Proxy{
585-
Conn: newUPDConnLocalhost(t),
585+
Conn: newUDPConnLocalhost(t),
586586
ServerAddr: ln.Addr().(*net.UDPAddr),
587587
DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 },
588588
}

0 commit comments

Comments
 (0)