caddy
caddy copied to clipboard
h2c server allows graceful shutdown
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.
@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.
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
Upstream pr has been submitted, I wonder how long that will take, since http2.Transport.DialTlsContext is stuck there for months.
I wonder how long that will take, since https://github.com/golang/net/pull/123 is stuck there for months.
Yeah... I've been waiting for a long time for that one 😩
Awesome, thank you so much for helping with this @WeidiDeng