From 183d351b5831b54460610acb56f1cb40d8a3d77d Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 17 Feb 2026 21:44:30 +0000 Subject: [PATCH] chore(pmtud/icmp): do not use net.ErrClosed when inappropriate --- internal/pmtud/icmp/errors.go | 4 ++-- internal/pmtud/icmp/icmp.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/pmtud/icmp/errors.go b/internal/pmtud/icmp/errors.go index 277c5551..4a9c3e97 100644 --- a/internal/pmtud/icmp/errors.go +++ b/internal/pmtud/icmp/errors.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net" "strings" "time" ) @@ -15,6 +14,7 @@ var ( ErrCommunicationAdministrativelyProhibited = errors.New("communication administratively prohibited") ErrBodyUnsupported = errors.New("ICMP body type is not supported") ErrMTUNotFound = errors.New("MTU not found") + errTimeout = errors.New("operation timed out") ) func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration) error { //nolint:revive @@ -22,7 +22,7 @@ func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration) case strings.HasSuffix(err.Error(), "sendto: operation not permitted"): err = fmt.Errorf("%w", ErrNotPermitted) case errors.Is(timedCtx.Err(), context.DeadlineExceeded): - err = fmt.Errorf("%w (timed out after %s)", net.ErrClosed, pingTimeout) + err = fmt.Errorf("%w: after %s", errTimeout, pingTimeout) case timedCtx.Err() != nil: err = timedCtx.Err() } diff --git a/internal/pmtud/icmp/icmp.go b/internal/pmtud/icmp/icmp.go index 8e9b9acb..07043060 100644 --- a/internal/pmtud/icmp/icmp.go +++ b/internal/pmtud/icmp/icmp.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net" "net/netip" "time" @@ -26,7 +25,7 @@ func PathMTUDiscover(ctx context.Context, ip netip.Addr, switch { case err == nil: return mtu, nil - case errors.Is(err, net.ErrClosed) || errors.Is(err, ErrCommunicationAdministrativelyProhibited): // blackhole + case errors.Is(err, errTimeout) || errors.Is(err, ErrCommunicationAdministrativelyProhibited): // blackhole default: return 0, fmt.Errorf("finding IPv4 next hop MTU: %w", err) } @@ -36,7 +35,7 @@ func PathMTUDiscover(ctx context.Context, ip netip.Addr, switch { case err == nil: return mtu, nil - case errors.Is(err, net.ErrClosed): // blackhole + case errors.Is(err, errTimeout): // blackhole default: return 0, fmt.Errorf("getting IPv6 packet-too-big message: %w", err) }