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: cancelation semantics with custom round tripper have changed in 1.14 #36820

ianlancetaylor opened this issue Jan 28, 2020 · 2 comments


Copy link

@ianlancetaylor ianlancetaylor commented Jan 28, 2020

The behavior of this program has changed in 1.14. This is, of course, cut down from a real program.

package main

import (

func main() {
	r, err := http.NewRequest("GET", "myproto://dummy", nil)
	if err != nil {
	var t http.Transport
	t.RegisterProtocol("myproto", &myRoundTripper{})
	c := &http.Client{
		Transport: &t,
		Timeout:   time.Second,
	_, err = c.Do(r)
	if err == nil {
		log.Fatal("expected timeout")

type myRoundTripper struct{}

func (*myRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	select {
	case <-req.Cancel:
		return nil, errors.New("round trip canceled as expected")
	case <-time.After(5 * time.Second):
		log.Fatal("round trip was not canceled")
		return nil, errors.New("round trip was not canceled")

With Go 1.13 I see this:

Get myproto://dummy: round trip canceled as expected (Client.Timeout exceeded while awaiting headers)

With tip I see this:

2020/01/27 16:12:46 round trip was not canceled
exit status 1
Copy link
Contributor Author

@ianlancetaylor ianlancetaylor commented Jan 28, 2020

Testing a patch.

Copy link

@gopherbot gopherbot commented Jan 28, 2020

Change mentions this issue: net/http: don't treat alternate protocol as known round tripper

@gopherbot gopherbot closed this in c436ead Jan 29, 2020
@golang golang locked and limited conversation to collaborators Jan 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants