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

h2c server allows graceful shutdown #4907

Open
WeidiDeng opened this issue Jul 25, 2022 · 5 comments · May be fixed by #4920
Open

h2c server allows graceful shutdown #4907

WeidiDeng opened this issue Jul 25, 2022 · 5 comments · May be fixed by #4920
Labels
bug 🐞 Something isn't working help wanted 🆘 Extra attention is needed upstream ⬆️ Relates to some dependency of this project

Comments

@WeidiDeng
Copy link
Member

Similar to websocket, h2c server internally upgrade the request and pass the resulting conn to http2 server to demux the stream to http handler.

Currently, h2c request, just like websocket, were left on their own. At least we can add ConfigureServer, which internally register graceful h2 shutdown on server shutdown.

If really wants to properly cleanup, perhaps just copy the h2c.go file and make some modifications. It's just 225 lines.

@mholt
Copy link
Member

mholt commented Jul 25, 2022

@WeidiDeng That's good to know. We'll need to look into this. I appreciate you bringing it to our attention!

Copying over 200 lines of code would be a bummer. But if there's no other way, maybe that's just what we'll have to do.

@mholt mholt added bug 🐞 Something isn't working help wanted 🆘 Extra attention is needed labels Jul 25, 2022
@WeidiDeng
Copy link
Member Author

Copying code is indeed such a chore.

Alternatively, I can think of another way. h2c check condition is pretty easy to copy, but we cannot access the net.Conn after the hijack call. One way would be specify a http.Server.ConnContext to record the underlying net.Conn and extract the net.Conn. Using BaseContext and a custom listener is also an option, but I think that's an overkill.

Besides this, h2c handler has another bug to fix (but that doesn't affect caddy that much, because caddy specific context key uses caddy's own), h2c handler won't extract the correct http.Server instance from the request itself, I'll push a pr upstream. This causes a number of issues 52868, 37089

@WeidiDeng
Copy link
Member Author

Upstream pr has been submitted, I wonder how long that will take, since http2.Transport.DialTlsContext is stuck there for months.

@francislavoie
Copy link
Member

I wonder how long that will take, since golang/net#123 is stuck there for months.

Yeah... I've been waiting for a long time for that one 😩

@mholt mholt added the upstream ⬆️ Relates to some dependency of this project label Jul 25, 2022
@mholt
Copy link
Member

mholt commented Jul 25, 2022

Awesome, thank you so much for helping with this @WeidiDeng

@WeidiDeng WeidiDeng linked a pull request Jul 29, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working help wanted 🆘 Extra attention is needed upstream ⬆️ Relates to some dependency of this project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants