Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: Client returns "request canceled" on timeout #17711

Closed
abhinav opened this issue Oct 31, 2016 · 2 comments

Comments

Projects
None yet
5 participants
@abhinav
Copy link
Contributor

commented Oct 31, 2016

Please answer these questions before submitting your issue. Thanks!

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

$ go version
go version go1.7.3 darwin/amd64

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

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/abg/dev/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.3/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8z/qdzjsr3n5l72vdg67zr6xkjc0000gn/T/go-build965147697=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"time"
)

func main() {
	req, err := http.NewRequest("GET", "https://httpbin.org/delay/3", nil)
	if err != nil {
		log.Fatal(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
	defer cancel()

	_, err = http.DefaultClient.Do(req.WithContext(ctx))
	fmt.Printf("err = %v (%T)\n", err, err)
	fmt.Printf("ctx.Err() = %v (%T)\n", ctx.Err(), ctx.Err())
}

What did you expect to see?

err = context deadline exceeded (context.deadlineExceededError)
ctx.Err() = context deadline exceeded (context.deadlineExceededError)

err should be a "context deadline exceeded" error and it should be the same as ctx.Error().

What did you see instead?

err and ctx.Error() are different. err is a "request canceled" error even though the context's cancel() hasn't been called yet.

err = Get https://httpbin.org/delay/3: net/http: request canceled while waiting for connection (*url.Error)
ctx.Err() = context deadline exceeded (context.deadlineExceededError)

Related to #16381, which was addressed in ctxhttp using,

if err != nil {
	select {
	case <-ctx.Done():
		err = ctx.Err()
	default:
	}
}

@bradfitz bradfitz added this to the Go1.8Maybe milestone Oct 31, 2016

@bradfitz bradfitz self-assigned this Oct 31, 2016

@bradfitz bradfitz changed the title http: Client returns "request canceled" on timeout net/http: Client returns "request canceled" on timeout Oct 31, 2016

abhinav added a commit to yarpc/yarpc-go that referenced this issue Oct 31, 2016

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 1, 2016

@odeke-em, was there a CL for this?

@odeke-em

This comment has been minimized.

Copy link
Member

commented Nov 1, 2016

Yap, there is https://go-review.googlesource.com/#/c/24230 but it's been stalled. Also seems like this issue is a duplicate of #16094.

@quentinmit quentinmit added the NeedsFix label Nov 8, 2016

@bradfitz bradfitz closed this Nov 10, 2016

@golang golang locked and limited conversation to collaborators Nov 10, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.