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: add clean way to stop a no-content-length transfer from an HTTP2 Server #22604

Closed
agirbal opened this issue Nov 6, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@agirbal
Copy link

commented Nov 6, 2017

With HTTP2 there is no more chunked encoding, instead it's built into the stream system. Now in many use cases the server may proxy responses back from other systems, or generate them on the fly, in which cases there is no content-length. It is possible that the proxying / processing breaks, and then it's not clear how to communicate the breakage to the client. If you just return the handler, the HTTP2 library will wrap it up like nothing happened and user will get truncated data.

With HTTP1, the common trick is to just hijack and close the connection. This works well.

	if err == io.ErrUnexpectedEOF {
		// the upstream closed on us ungracefully.
		// if no content-length, need to notify downstream that content is incomplete.
		// In HTTP1.1 means closing connection, which requires hijacking.
		if rw.Header().Get("Content-Length") == "" {
			if hj, ok := rw.(http.Hijacker); ok {
				conn, _, _ := hj.Hijack()
				conn.Close()
			}
		}
	}

A similar question for HTTP2 was asked here #14797
To which the answer from @bradfitz was to just panic. But this seems messy since the app may still have other processing to do related to this request, and at minimum things like access logging. It just feels unnatural to panic in this case, and difficult to understand what truly happens over Go revisions without testing (does stream get closed? Or just will time out?).

Would it be possible to expose the equivalent of a Hijack for HTTP2 streams, where one could explicitly abort the stream if needed?
Thanks!

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

1.9.2

Does this issue reproduce with the latest release?

yes

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

osx

What did you do?

What did you expect to see?

What did you see instead?

@ianlancetaylor ianlancetaylor changed the title With HTTP2, way to abort a no-content-length transfer from Server net/http: add clean way to stop a no-content-length transfer from an HTTP2 Server Nov 6, 2017

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Nov 6, 2017

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Nov 6, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 7, 2017

https://golang.org/pkg/net/http/#ErrAbortHandler was added in Go 1.8 explicitly for this purpose. It's tested and documented.

You may not like panicking as the answer, and we don't exactly either, but it's where we ended up.

@bradfitz bradfitz closed this Nov 7, 2017

@golang golang locked and limited conversation to collaborators Nov 7, 2018

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.