hackney_pool (hackney v2.0.0-beta.1)
View SourcePool of connection processes.
This module manages hackney_conn processes in a pool. Instead of storing raw sockets, it tracks connection process pids. Idle timeout is handled by the connection processes themselves (gen_statem state_timeout).
Summary
Functions
Return a connection process to the pool.
Checkout a connection process from the pool. Returns {ok, PoolInfo, Pid} where Pid is a hackney_conn process.
Get an existing HTTP/2 connection for a host/port, or 'none' if not available. HTTP/2 connections are shared (multiplexed) across callers.
Get an existing HTTP/3 connection for a host/port, or 'none' if not available. HTTP/3 connections are shared (multiplexed) across callers via QUIC streams.
return a child spec suitable for embedding your pool in the supervisor
get the number of connections in the pool
get the number of connections in the pool for {Host, Port, Transport}
Get per-host connection statistics. Returns a proplist with: - active: number of active requests (from load_regulation) - in_use: connections checked out from pool - free: connections available in pool
get max pool size
Prewarm connections to a host (default count from pool settings) Starts the pool if it doesn't exist.
Prewarm a specific number of connections to a host Starts the pool if it doesn't exist.
Register an HTTP/2 connection in the pool for sharing. Called after ALPN negotiation confirms HTTP/2.
Register an HTTP/3 connection in the pool for sharing. Called after QUIC connection is established with HTTP/3.
change the pool size
change the connection timeout
start a pool
stop a pool
get timeout
Remove an HTTP/2 connection from the pool (e.g., on GOAWAY).
Remove an HTTP/3 connection from the pool (e.g., on connection close).
Functions
Return a connection process to the pool.
-spec checkout(Host :: string(), Port :: non_neg_integer(), Transport :: module(), Options :: list()) -> {ok, term(), pid()} | {error, term()}.
Checkout a connection process from the pool. Returns {ok, PoolInfo, Pid} where Pid is a hackney_conn process.
-spec checkout_h2(Host :: string(), Port :: non_neg_integer(), Transport :: module(), Options :: list()) -> {ok, pid()} | none.
Get an existing HTTP/2 connection for a host/port, or 'none' if not available. HTTP/2 connections are shared (multiplexed) across callers.
-spec checkout_h3(Host :: string(), Port :: non_neg_integer(), Transport :: module(), Options :: list()) -> {ok, pid()} | none.
Get an existing HTTP/3 connection for a host/port, or 'none' if not available. HTTP/3 connections are shared (multiplexed) across callers via QUIC streams.
return a child spec suitable for embedding your pool in the supervisor
get the number of connections in the pool
get the number of connections in the pool for {Host, Port, Transport}
-spec host_stats(atom(), string() | binary(), inet:port_number()) -> [{atom(), non_neg_integer()}].
Get per-host connection statistics. Returns a proplist with: - active: number of active requests (from load_regulation) - in_use: connections checked out from pool - free: connections available in pool
get max pool size
-spec prewarm(atom(), string() | binary(), inet:port_number()) -> ok.
Prewarm connections to a host (default count from pool settings) Starts the pool if it doesn't exist.
-spec prewarm(atom(), string() | binary(), inet:port_number(), non_neg_integer()) -> ok.
Prewarm a specific number of connections to a host Starts the pool if it doesn't exist.
-spec register_h2(Host :: string(), Port :: non_neg_integer(), Transport :: module(), Pid :: pid(), Options :: list()) -> ok.
Register an HTTP/2 connection in the pool for sharing. Called after ALPN negotiation confirms HTTP/2.
-spec register_h3(Host :: string(), Port :: non_neg_integer(), Transport :: module(), Pid :: pid(), Options :: list()) -> ok.
Register an HTTP/3 connection in the pool for sharing. Called after QUIC connection is established with HTTP/3.
change the pool size
change the connection timeout
start a pool
stop a pool
get timeout
Remove an HTTP/2 connection from the pool (e.g., on GOAWAY).
Remove an HTTP/3 connection from the pool (e.g., on connection close).