tstest/natlab: use net.ErrClosed instead of a new error

Upstream wireguard-go decided to use errors.Is(err, net.ErrClosed)
instead of checking the error string.

It also provided an unsafe linknamed version of net.ErrClosed
for clients running Go 1.15. Switch to that.

This reduces the time required for the wgengine/magicsock tests
on my machine from ~35s back to the ~13s it was before
456cf8a376.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
pull/1279/head
Josh Bleecher Snyder 4 years ago committed by Josh Bleecher Snyder
parent ace57d7627
commit 138055dd70

@ -59,6 +59,7 @@ func runSTUN(t *testing.T, pc net.PacketConn, stats *stunStats, done chan<- stru
for { for {
n, addr, err := pc.ReadFrom(buf[:]) n, addr, err := pc.ReadFrom(buf[:])
if err != nil { if err != nil {
// TODO: when we switch to Go 1.16, replace this with errors.Is(err, net.ErrClosed)
if strings.Contains(err.Error(), "closed network connection") { if strings.Contains(err.Error(), "closed network connection") {
t.Logf("STUN server shutdown") t.Logf("STUN server shutdown")
return return

@ -26,6 +26,7 @@ import (
"sync" "sync"
"time" "time"
wgconn "github.com/tailscale/wireguard-go/conn"
"inet.af/netaddr" "inet.af/netaddr"
) )
@ -758,7 +759,8 @@ func (c *conn) canRead() error {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
if c.closed { if c.closed {
return errors.New("closed network connection") // sadface: magic string used by other; don't change // TODO: when we switch to Go 1.16, replace this with net.ErrClosed
return wgconn.NetErrClosed
} }
if !c.readDeadline.IsZero() && c.readDeadline.Before(time.Now()) { if !c.readDeadline.IsZero() && c.readDeadline.Before(time.Now()) {
return errors.New("read deadline exceeded") return errors.New("read deadline exceeded")

Loading…
Cancel
Save