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

x/net/http2/h2c: support closure of all connections and graceful shutdown #26682

Open
nhooyr opened this issue Jul 30, 2018 · 5 comments
Open

x/net/http2/h2c: support closure of all connections and graceful shutdown #26682

nhooyr opened this issue Jul 30, 2018 · 5 comments
Labels
FeatureRequest NeedsInvestigation
Milestone

Comments

@nhooyr
Copy link
Contributor

@nhooyr nhooyr commented Jul 30, 2018

Very happy to see h2c supported: golang/net@c4299a1

However, there is no way to enable graceful shutdown, or even close all h2c connections. We should support this.

You could use http2.ConfigureServer to configure a http2 server's graceful shutdown to be called when the http server is shutdown but the http server's shutdown method will not wait for the http2 connections to close because they have been hijacked.

I think it'd be simplest if we added a Shutdown and Close method to *http2.Server analogous to *http.Server's methods.

@nhooyr nhooyr changed the title x/net/http2: support closure of all connections and graceful shutdown x/net/http2/h2c: support closure of all connections and graceful shutdown Jul 30, 2018
@gopherbot gopherbot added this to the Unreleased milestone Jul 30, 2018
@nhooyr nhooyr changed the title x/net/http2/h2c: support closure of all connections and graceful shutdown http2/h2c: support closure of all connections and graceful shutdown Jul 30, 2018
@obeattie
Copy link

@obeattie obeattie commented Oct 22, 2018

Is there a workaround possible for this? As far as I can see it's completely impossible to do at present, as the methods that need to be invoked to gracefully shutdown a connection (eg. serverConn.startGracefulShutdown) are unexported. cc. @bradfitz

@obeattie
Copy link

@obeattie obeattie commented Oct 22, 2018

After poking a bit more, it looks like I can do something like this, which is a pretty horrid hack but does appear to work:

h2s := &http2.Server{}
h1s := &http.Server{}
http2.ConfigureServer(h1s, h2s)
// Make use of h2s in a h2c handler…
h1s.Shutdown(ctx)

This works because http2.ConfigureServer adds a shutdown hook into the http.Server such that when its Shutdown() method is invoked, the private startGracefulShutdown method is called. Shutdown() calls this method regardless of the fact that h1s was never "used."

@nhooyr
Copy link
Contributor Author

@nhooyr nhooyr commented Oct 22, 2018

That does not work as the Shutdown itself doesn't wait for the h2c connections.

See

go f()

It starts the graceful shutdown of h2c connections in a new goroutine but only wait for the unhijacked connections.

@agnivade agnivade changed the title http2/h2c: support closure of all connections and graceful shutdown x/net/http2/h2c: support closure of all connections and graceful shutdown Oct 23, 2018
@agnivade agnivade added NeedsInvestigation FeatureRequest labels Oct 23, 2018
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Oct 24, 2018

Sorry, h2c is super low on my priority list. I don't have time to investigate this enough to be helpful here.

obeattie added a commit to monzo/typhon that referenced this issue Oct 25, 2018
Connections that were upgraded to HTTP/2 by use of the H2cFilter can now be drained properly. The implementation is pretty ugly because Go does not have native support for connection draining on h2c connections, and as per golang/go#26682 this isn't a priority for the project.
obeattie added a commit to monzo/typhon that referenced this issue Oct 28, 2018
Connections that were upgraded to HTTP/2 by use of the H2cFilter can now be drained properly. The implementation is pretty ugly because Go does not have native support for connection draining on h2c connections, and as per golang/go#26682 this isn't a priority for the project.
obeattie added a commit to monzo/typhon that referenced this issue Nov 15, 2018
Connections that were upgraded to HTTP/2 by use of the H2cFilter can now be drained properly. The implementation is pretty ugly because Go does not have native support for connection draining on h2c connections, and as per golang/go#26682 this isn't a priority for the project.
obeattie added a commit to monzo/typhon that referenced this issue Nov 16, 2018
Connections that were upgraded to HTTP/2 by use of the H2cFilter can now be drained properly. The implementation is pretty ugly because Go does not have native support for connection draining on h2c connections, and as per golang/go#26682 this isn't a priority for the project.
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 5, 2019

Change https://golang.org/cl/185059 mentions this issue: http2: add Close and Shutdown functions to the Server.

AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Oct 1, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Oct 14, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Dec 22, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Dec 22, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Dec 22, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Dec 22, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Dec 22, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit to zalando/skipper that referenced this issue Dec 22, 2021
Enables HTTP/2 connections over cleartext TCP with Prior Knowledge (RFC 7540 3.4).

The implementation is based on the golang.org/x/net/http2/h2c and workarounds several issues:
* golang/go#38064
* golang/go#26682

See h2c package docs for details.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

5 participants