Skip to content

Fix HTTP/2 response leak.#219

Merged
ioquatix merged 1 commit intomainfrom
fix-http2-close-on-error
Apr 10, 2026
Merged

Fix HTTP/2 response leak.#219
ioquatix merged 1 commit intomainfrom
fix-http2-close-on-error

Conversation

@samuel-williams-shopify
Copy link
Copy Markdown
Contributor

@samuel-williams-shopify samuel-williams-shopify commented Apr 9, 2026

When an HTTP/2 client resets a stream before the server sends response headers (common with gRPC cancellation), request.send_response(response) raises ProtocolError: Cannot send headers in state: closed. The response body is never closed because there is no ensure guard on the send path. Any resources tied to body lifecycle — such as rack.response_finished callbacks and utilization metrics — are permanently leaked.

This was discovered via Falcon's requests_active utilization metric (tracked by Body::RequestFinished), which was never decremented on this error path. On clusters with gRPC traffic, each ProtocolError leaked +1 into requests_active permanently, producing a monotonically increasing gauge.

The fix adds ensure response&.close in Server#each, bringing the HTTP/2 server to parity with the HTTP/1 server which already had equivalent ensure body&.close(error) handling. The call is safe on all paths: on success the body is already closed by send_body and close is idempotent; on yield failure response is nil so the call is a no-op; on task cancellation ensure still runs after defer_stop.

Types of Changes

  • Bug fix.

Contribution

@samuel-williams-shopify samuel-williams-shopify force-pushed the fix-http2-close-on-error branch 3 times, most recently from 158aa40 to 1c5b346 Compare April 10, 2026 02:16
@ioquatix ioquatix merged commit f25091d into main Apr 10, 2026
34 of 40 checks passed
@ioquatix ioquatix deleted the fix-http2-close-on-error branch April 10, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants