Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for retiring old connections for HTTP clients. #179

Open
Tracked by #114
tobz opened this issue Aug 12, 2024 · 1 comment
Open
Tracked by #114

Add support for retiring old connections for HTTP clients. #179

tobz opened this issue Aug 12, 2024 · 1 comment
Labels
area/io General I/O and networking. effort/intermediate Involves changes that can be worked on by non-experts but might require guidance. type/enhancement An enhancement in functionality or support.

Comments

@tobz
Copy link
Member

tobz commented Aug 12, 2024

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.

@tobz tobz added area/io General I/O and networking. type/enhancement An enhancement in functionality or support. effort/intermediate Involves changes that can be worked on by non-experts but might require guidance. status/blocked Blocked on another issue or upstream dependency. labels Aug 12, 2024
@tobz
Copy link
Member Author

tobz commented Aug 12, 2024

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:

  • in HttpClient::send, use capture_connection to get Connected for the connection used for the request
  • check the response extensions and look for a new type we'll call ConnectionAge (we'll create this as a newtype wrapper around std::time::Instant)
  • if we can't find it in the response extensions, we'll create one based on the current time and attach it to the connection via Connected::extra
  • if we do find it, we'll see if the connection is older than the configured TTL, and if so, poison the connection via 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.

@tobz tobz removed the status/blocked Blocked on another issue or upstream dependency. label Aug 13, 2024
@tobz tobz added this to the ADP v0.3: Production Bound milestone Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/io General I/O and networking. effort/intermediate Involves changes that can be worked on by non-experts but might require guidance. type/enhancement An enhancement in functionality or support.
Projects
None yet
Development

No branches or pull requests

1 participant