Repository navigation
Implement two-phase graceful shutdown for HTTP/2 server connections, as recommended by RFC 9113 section 6.8. - #743
Conversation
|
Hi @arturobernalg, nice work on this one 👍 I tried it against a raw-socket H2 client and the main case works: a request that shows up after the first GOAWAY gets served and the final GOAWAY comes back with One thing I ran into: if the peer never answers the PING, the Setup: server with
With the default Full matrix (master / this PR / local tweak)
To check it, I tried a small local change: while the probe is pending, set the session socket timeout to // executeShutdown(), server branch
if (!pingAckTimeout.isDisabled()) {
gracefulShutdownSavedSocketTimeout = ioSession.getSocketTimeout();
ioSession.setSocketTimeout(pingAckTimeout);
}
// onTimeout()
if (gracefulShutdownAwaitingPing) {
completeGracefulShutdown(); // also restores the saved socket timeout
requestSessionOutput();
return;
}But I noticed the tests check There's also the |
3403ddf to
081878a
Compare
|
Good catch — you were right, this was a real bug. Pushed a fix: the GOAWAY probe now bounds itself by temporarily shortening the session timeout (capped at 1s) instead of relying on I/O events a silent peer never generates. Also added a real end-to-end test for this exact scenario, a raw-socket client that never ACKs the PING, covering both close(CloseMode.GRACEFUL) and initiateShutdown()/awaitShutdown() — green. Could you retest against your raw-socket client when you get a chance? |
Send an initial GOAWAY with the maximum stream ID, followed by a PING to allow in-flight requests to arrive before sending the final GOAWAY with the last accepted stream ID. A silent peer never triggers onInput()/onOutput(), so the PING ACK deadline was only ever checked opportunistically and never fired on its own. Bound the probe by temporarily shortening the session timeout to it (capped at 1s, well under the 5s grace an I/O reactor gives a graceful shutdown before forcing it closed), mirroring the same timeout swap/restore validateAfterInactivity already uses for its own PING round trip. onTimeout() now tells probe expiry (send the final GOAWAY) apart from a genuine dead connection (unchanged hard-kill behavior). Add a real-server integration test with a raw-socket client that never ACKs the PING, covering both close(CloseMode.GRACEFUL) and initiateShutdown()/awaitShutdown().
081878a to
0517824
Compare
|
Retested 0517824 with the same raw-socket client and it looks good now 🎉 A silent peer gets the final GOAWAY after ~1s with both close(GRACEFUL) and initiateShutdown()/awaitShutdown(), including with the default soTimeout of 0. The ACK and in-flight request cases still work as before. I also tried a request whose body shows up 3s later without a PING ACK: the final GOAWAY goes out at ~1s with last=1, and the request still completes with a 200. Thanks for the quick fix! |
Implement two-phase graceful shutdown for HTTP/2 server connections, as recommended by RFC 9113 section 6.8.
The server first sends GOAWAY with the maximum stream ID, allowing requests already in transit to be processed. A PING exchange is then used to establish a round-trip interval before sending the final GOAWAY with the last accepted stream ID.
The implementation reuses the existing PING handling and timeout mechanisms without blocking the I/O reactor or introducing additional scheduling infrastructure.
Client-side shutdown behavior remains unchanged.