Improve HTTP/2 GOAWAY handling to close idle connections early during graceful shutdown
Currently, when an HTTP/2 server connection enters graceful shutdown (after sending GOAWAY), it always waits for the full connectionDrainDuration before closing the connection, even if there are no active requests. This leads to unnecessary resource consumption and slower connection cleanup during server shutdown or connection recycling scenarios.
Current behavior
- Server sends initial GOAWAY frame with stream ID Integer.MAX_VALUE to signal imminent shutdown
- Waits for the full drain duration
- Sends final GOAWAY and closes connection
Proposed Improvement
Implement an event-driven mechanism to close HTTP/2 connections immediately when no active requests remain during the drain phase. This would:
- Track active requests during connection draining
- Fire an event when the last active request completes (or immediately if no requests are active when draining starts)
- Cancel the scheduled drain timeout and close the connection early
Please let me know if my understanding is correct and if the proposal is reasonbale!
close HTTP/2 connections immediately when no active requests remain during the drain phase.
In-flight requests sent before a GOAWAY is received should be properly handled. Closing idle connections that have no active requests immediately could compromise a graceful shutdown.