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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

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 ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Jan 28, 2020
@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Jan 28, 2020
@ianlancetaylor
Copy link
Contributor Author

Testing a patch.

@gopherbot
Copy link

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

@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.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants