Add graceful HTTP/2 connection draining via max_connection_age#364
Open
procmarchal wants to merge 2 commits intosneako:mainfrom
Open
Add graceful HTTP/2 connection draining via max_connection_age#364procmarchal wants to merge 2 commits intosneako:mainfrom
procmarchal wants to merge 2 commits intosneako:mainfrom
Conversation
Add graceful HTTP/2 connection draining via max_connection_age Introduces two new `http2:` pool options — `max_connection_age` and `max_connection_age_jitter` — that let Finch proactively recycle HTTP/2 connections after a configured lifetime. This enables client-side load balancing against Kubernetes headless services, where long-lived HTTP/2 connections would otherwise stay pinned to a single pod. When the age timer fires the pool unregisters itself from the Registry (so new requests are immediately routed elsewhere), finishes any in-flight requests in `:connected_read_only`, then terminates normally. The supervisor restarts it with a fresh DNS lookup. Requests that land on a draining pool via `request/3`, `stream/5`, or `stream_while/5` are transparently retried (up to 3 times); `async_request/3` callers receive the `:read_only` error and must retry manually (documented in the @doc). Made-with: Cursor
NelsonVides
reviewed
Apr 14, 2026
Collaborator
NelsonVides
left a comment
There was a problem hiding this comment.
All right! My first thought was that this is not a feature I'd use and therefore performance-wise didn't want to pay the price for it. But then I checked the code and well, I don't think there'd be any relevant performance penalty, the implementation is very clean! Then I thought well, wait, maybe actually I do have a use case for this. Then I read the code again and thought: thank you!
Ok, first thing, could you rebase on top of the latest master and resolve conflicts? 🙏🏽
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add graceful HTTP/2 connection draining via max_connection_age
Fixes #363
Approach
Introduces two new
http2:pool options —max_connection_ageandmax_connection_age_jitter— that let Finch proactively recycle HTTP/2 connections after a configured lifetime. This enables client-side load balancing against Kubernetes headless services, where long-lived HTTP/2 connections would otherwise stay pinned to a single pod.When the age timer fires the pool unregisters itself from the Registry (so new requests are immediately routed elsewhere), finishes any in-flight requests in
:connected_read_only, then terminates normally. The supervisor restarts it with a fresh DNS lookup. Requests that land on a draining pool viarequest/3,stream/5, orstream_while/5are transparently retried (up to 3 times);async_request/3callers receive the:read_onlyerror and must retry manually (documented in the @doc).