Open tobz opened 1 month ago
Actually, looking at the new additions to hyper-util@v0.1.7
, we might be able to use the ported "poison pill" behavior to poison a connection after we get a response and determine the connection is old enough.
Essentially:
HttpClient::send
, use capture_connection
to get Connected
for the connection used for the requestConnectionAge
(we'll create this as a newtype wrapper around std::time::Instant
)Connected::extra
Connected::poison
A poisoned connection won't be returned to the idle pool, so in effect, we're able to mark these connections as no longer usable, and thereby ensuring they get rolled. This is a little lossy, because we're poisoning them right after they get back into the pool, really... and the connection age is attached after the response arrives, so they must end up a few seconds older in reality than what we'd measure if we tracked the actual moment the connection was created.
All of that said, though... it should be more than satisfactory for our purposes.
Context
When building an HTTP client, we should be able to configure a time-to-live for all pooled connections, such that an individual connection that is idle can never be older than the configured TTL. This is useful for ensuring that new connections are periodically established to the downstream target system, aiding in scenarios like switching over to newly provisioned IPs when load balancer nodes are being replaced, etc.
Notes
This is not something currently exposed by
hyper-util
but I think, conceptually, could be easy enough to upstream.