From 72b0fb5153765fef92290a7c3eb816201bbd20fd Mon Sep 17 00:00:00 2001 From: Ben Burkert Date: Thu, 29 Mar 2018 15:04:58 -0700 Subject: [PATCH] net: map context errors from aborted dial to internal net package errors Map the error returned when a dial is aborted from the context package error to the internal net package error. For example, context.Canceled errors map to errCanceled, and context.DeadlineExceeded errors map to poll.ErrTimeout. Fixes #23648 Change-Id: Idf9d3d08052d540740c0b054503aaed931dc5b1e Reviewed-on: https://go-review.googlesource.com/103518 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/dial_unix_test.go | 5 +++-- src/net/fd_unix.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/net/dial_unix_test.go b/src/net/dial_unix_test.go index 4705254728..0adc10d0bd 100644 --- a/src/net/dial_unix_test.go +++ b/src/net/dial_unix_test.go @@ -102,7 +102,8 @@ func TestDialContextCancelRace(t *testing.T) { if !ok || oe.Op != "dial" { t.Fatalf("Dial error = %#v; want dial *OpError", err) } - if oe.Err != ctx.Err() { - t.Errorf("DialContext = (%v, %v); want OpError with error %v", c, err, ctx.Err()) + + if oe.Err != errCanceled { + t.Errorf("DialContext = (%v, %v); want OpError with error %v", c, err, errCanceled) } } diff --git a/src/net/fd_unix.go b/src/net/fd_unix.go index dd3c1ed882..efe2e184af 100644 --- a/src/net/fd_unix.go +++ b/src/net/fd_unix.go @@ -121,7 +121,7 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysc // == nil). Because we've now poisoned the connection // by making it unwritable, don't return a successful // dial. This was issue 16523. - ret = ctxErr + ret = mapErr(ctxErr) fd.Close() // prevent a leak } }() -- 2.48.1