Secure, Fast, and Extensible Sandbox runtime for AI agents.
test(egress): bind the large-answer DNS upstream on a port free for both
Maohao2e9a5845da6b
diff --git a/components/egress/pkg/dnsproxy/proxy_test.go b/components/egress/pkg/dnsproxy/proxy_test.goindex 7ff7b0eb3..7dd5e39cb 100644--- a/components/egress/pkg/dnsproxy/proxy_test.go+++ b/components/egress/pkg/dnsproxy/proxy_test.go@@ -474,10 +474,7 @@ func startLargeAnswerUpstream(t *testing.T, records int) string {_ = w.WriteMsg(resp)})- packetConn, err := net.ListenPacket("udp", "127.0.0.1:0")- require.NoError(t, err)- listener, err := net.Listen("tcp", packetConn.LocalAddr().String())- require.NoError(t, err)+ packetConn, listener := listenUDPAndTCPOnOnePort(t)for _, server := range []*dns.Server{{PacketConn: packetConn, Handler: handler},{Listener: listener, Handler: handler},@@ -491,6 +488,23 @@ func startLargeAnswerUpstream(t *testing.T, records int) string {return packetConn.LocalAddr().String()}+// listenUDPAndTCPOnOnePort binds UDP and TCP on the same free port, retrying+// when the TCP side of the port the UDP socket got is already taken.+func listenUDPAndTCPOnOnePort(t *testing.T) (net.PacketConn, net.Listener) {+ t.Helper()+ for range 10 {+ packetConn, err := net.ListenPacket("udp", "127.0.0.1:0")+ require.NoError(t, err)+ listener, err := net.Listen("tcp", packetConn.LocalAddr().String())+ if err == nil {+ return packetConn, listener+ }+ _ = packetConn.Close()+ }+ t.Fatal("no port free for both UDP and TCP")+ return nil, nil+}+// A client retries over TCP after a truncated UDP answer; that retry must// reach the upstream over TCP too, or the answer stays truncated.func TestServeDNSForwardsTCPQueriesOverTCP(t *testing.T) {