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

Closed
ianlancetaylor opened this issue Jan 28, 2020 · 2 comments
Closed

Comments

@ianlancetaylor
Copy link
Contributor

@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 (
	"errors"
	"fmt"
	"log"
	"net/http"
	"time"
)

func main() {
	r, err := http.NewRequest("GET", "myproto://dummy", nil)
	if err != nil {
		log.Fatal(err)
	}
	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")
	}
	fmt.Println(err)
}

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
@ianlancetaylor
Copy link
Contributor Author

@ianlancetaylor ianlancetaylor commented Jan 28, 2020

Testing a patch.

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 28, 2020

Change https://golang.org/cl/216618 mentions this issue: net/http: don't treat alternate protocol as known round tripper

@gopherbot gopherbot closed this in c436ead Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.