From 783616f61da8da0bb7f46d8e369e19e7e666d813 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Thu, 19 Feb 2026 12:22:42 +0000 Subject: [PATCH] chore(pmtud/tcp): close connections with an RST packet on context cancelation --- internal/pmtud/tcp/tcp.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/pmtud/tcp/tcp.go b/internal/pmtud/tcp/tcp.go index b7b798ef..6b9cc171 100644 --- a/internal/pmtud/tcp/tcp.go +++ b/internal/pmtud/tcp/tcp.go @@ -107,6 +107,7 @@ func runTest(ctx context.Context, dst netip.AddrPort, mtu uint32, var reply []byte select { case <-ctx.Done(): + _ = sendRST(fd, src, dst, synSeq+1) return ctx.Err() case reply = <-ch: } @@ -149,6 +150,7 @@ func runTest(ctx context.Context, dst netip.AddrPort, mtu uint32, select { case <-ctx.Done(): + _ = sendRST(fd, src, dst, firstReplyHeader.ack) return ctx.Err() case reply = <-ch: } @@ -180,7 +182,7 @@ var errTCPPacketNotRST = errors.New("TCP packet is not an RST") func handleRSTReply(ctx context.Context, fd fileDescriptor, ch <-chan []byte, src, dst netip.AddrPort, mtu uint32, ) error { - packet, _ := createSYNPacket(src, dst, mtu) + packet, synSeq := createSYNPacket(src, dst, mtu) const sendToFlags = 0 err := sendTo(fd, packet, sendToFlags, makeSockAddr(dst)) if err != nil { @@ -190,6 +192,7 @@ func handleRSTReply(ctx context.Context, fd fileDescriptor, ch <-chan []byte, var reply []byte select { case <-ctx.Done(): + _ = sendRST(fd, src, dst, synSeq+1) return ctx.Err() // timeout: the MTU test SYN packet was too big case reply = <-ch: }