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"