From ecaa4cfc1a8823d28708335934a24abdcca3246d Mon Sep 17 00:00:00 2001 From: WolfDan <5377526+WolfDan@users.noreply.github.com> Date: Tue, 28 Oct 2025 20:00:10 -0500 Subject: [PATCH] limit max connections to server value on http2 connections --- lib/finch/pool_manager.ex | 15 +++++++++++++++ mise.toml | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 mise.toml diff --git a/lib/finch/pool_manager.ex b/lib/finch/pool_manager.ex index 6d8f141..332824d 100644 --- a/lib/finch/pool_manager.ex +++ b/lib/finch/pool_manager.ex @@ -143,8 +143,23 @@ defmodule Finch.PoolManager do |> Map.get(shp, default) |> maybe_drop_tls_options(shp) |> maybe_add_hostname(shp) + |> maybe_update_count(shp) end + defp maybe_update_count(%{count: count, mod: Finch.HTTP2.Pool} = config, {scheme, host, port}) do + with {:ok, conn} <- Mint.HTTP2.connect(scheme, host, port) do + max_concurrent_streams = + Mint.HTTP2.get_server_setting(conn, :max_concurrent_streams) || count + + count = min(count, max_concurrent_streams) + Map.put(config, :count, count) + else + _ -> config + end + end + + defp maybe_update_count(config, _), do: config + # Drop TLS options from :conn_opts for default pools with :http scheme, # otherwise you will get :badarg error from :gen_tcp defp maybe_drop_tls_options(config, {:http, _, _} = _shp) when is_map(config) do diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..7ddd7a8 --- /dev/null +++ b/mise.toml @@ -0,0 +1,3 @@ +[tools] +elixir = "latest" +erlang = "latest"