Skip to content

net: expose original context Canceled/DeadlineExceeded error #28529

Closed
@ifraixedes

Description

@ifraixedes

My apologies if this is already reported however, I haven't been able to find something about in the issue tracker.

What version of Go are you using (go version)?

Go 1.10.4

Does this issue reproduce with the latest release?

I believe that I would have the same problem in Go 1.11.1 (as far as I can see in the sources of the master branch of this mirror repository)

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/go/bin"
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/root/apps/go"
GOTMPDIR=""
GOTOOLDIR="/root/apps/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build649898996=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Mostly, if I call net/Dialer.DialContext and the passed context is canceled, I cannot compare the error wrapped by net.OpError (Err attribute) with context.Canceled variable in order to distinguish this error of any other.

Why?

Because net/Dialer.DialContext calls dialSerial which in case that the context is canceled, it replaces the context.Canceled by an unexported error before assigning to net.OpError.Err (carried by the unexported function mapErr)

The same happens with the context.DeadlineExceeded

What did you expect to see?

Have the original context error in the OpError.Err attribute.

What did you see instead?

What I've described above, but I cannot simply figure it out if the error returned is one of the ones returned by context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions