@@ -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
574573func 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 ,
0 commit comments