armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Improve HTTP/2 GOAWAY handling to close idle connections early during graceful shutdown

Open yzfeng2020 opened this issue 3 months ago • 1 comments

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

  1. Server sends initial GOAWAY frame with stream ID Integer.MAX_VALUE to signal imminent shutdown
  2. Waits for the full drain duration
  3. 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:

  1. Track active requests during connection draining
  2. Fire an event when the last active request completes (or immediately if no requests are active when draining starts)
  3. 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!

yzfeng2020 avatar Sep 03 '25 22:09 yzfeng2020

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.

ikhoon avatar Sep 04 '25 02:09 ikhoon