class

Deadfinder::HttpClient::ConnectionPool

Inherits Reference < Object

Bounded pool of idle keep-alive clients, keyed by origin (plus the connection settings that shape the client, so a differently-configured run can never pick up a client built for the previous one).

Borrow/return, not share: checkout removes the client from the pool, so it is invisible to every other fiber until checkin puts it back. That exclusivity is the whole point — Crystal fibers yield on every socket read, so two fibers holding one HTTP::Client would interleave their requests on a single connection and read each other's responses.

Constants

MAX_IDLE_AGE = 20.seconds

Servers close idle keep-alive connections after a few seconds. Handing out one the peer already dropped costs a failed request plus a reconnect, so anything idle longer than this is closed on borrow.

MAX_IDLE_PER_ORIGIN = 64

Idle clients kept per origin. Chosen to sit above the default concurrency (50) so a single-host scan — the case the pool exists for — reuses every worker's connection instead of re-handshaking most of them.

MAX_IDLE_TOTAL = 64

Idle clients kept across all origins. A scan whose links fan out over hundreds of hosts would otherwise retain a few sockets per host and run the process out of file descriptors; past this point the least recently used connection is closed to make room.

Constructors

Instance methods

checkin(key : String, client : HTTP::Client) : Nil
Source
checkout(key : String) : HTTP::Client | Nil

Returns a client the caller now owns exclusively, or nil when the pool has nothing fresh for this origin.

Source
close_all
Source
discard(client : HTTP::Client) : Nil

A client whose request raised is never returned to the pool: the connection may be half-written or half-read, and reusing it would desynchronize the next response.

Source
idle_count(key : String) : Int32
Source
total_idle
Source

Nested types