Skip to content

Add "clientLifetime" option to close and remove connections from the pool after a specified time. #4175

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

Merged
merged 2 commits into from
May 12, 2025

Conversation

dhalbrook
Copy link
Contributor

This relates to...

This feature allows clients to be closed and removed from the pool after a specified amount of time.

Rationale

This feature can be helpful to avoid GOAWAY connection errors when dealing with HTTP2 connections where the amount of time they are valid for is known beforehand.

Changes

This adds a "clientLifetime" option to the Pool options allowing specification of a fixed lifetime for clients in mils

Bug Fixes

N/A

Status

@metcoder95
Copy link
Member

I'm under the impression that this can be already achieved through PoolOptions#factory; I'm happy either way, but it we want to land it in core I'd suggest to assign a more explicit name like ttl or something.

On top, consider the possibility of verify/preempt the client upon a request, so we reduce the surface for possible race conditions between removal and new upcoming request.

@dhalbrook
Copy link
Contributor Author

I'm under the impression that this can be already achieved through PoolOptions#factory;

I would have gone down that route but i'm not sure how to remove a client from the pool. That doesn't seem to be exposed anywhere in Pool.

@dhalbrook
Copy link
Contributor Author

I updated the logic to remove clients in the getDispatcher call when the TTL has passed. This should not add any significant overhead.

@dhalbrook
Copy link
Contributor Author

dhalbrook commented Apr 24, 2025

Ugh, I was trying to rebase my fork to hopefully fix the test issues and screwed up. Please re-approve when you get the chance. I squashed it down to one commit so it will be cleaner.

@dhalbrook dhalbrook reopened this Apr 24, 2025
@dhalbrook
Copy link
Contributor Author

dhalbrook commented Apr 26, 2025

Hi @metcoder95 Any idea why those tests might be failing? They don't seem related to may changes as far as I can tell.

@metcoder95
Copy link
Member

Yeah, these are flaky tests that needs to be fixed; but are not related to your changes.

@dhalbrook
Copy link
Contributor Author

Is there a way to re-run them until they pass?

@metcoder95
Copy link
Member

They will fail constantly. I hope I can have a fix soon

@dhalbrook
Copy link
Contributor Author

Hi @metcoder95 , I'm a bit bummed this didn't make it into the 7.9.0 release. What are the steps forward?

@metcoder95 metcoder95 requested review from mcollina and ronag May 12, 2025 06:40
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit faca33a into nodejs:main May 12, 2025
29 of 31 checks passed
@github-actions github-actions bot mentioned this pull request May 12, 2025
caitp pushed a commit to caitp/undici that referenced this pull request May 15, 2025
…after a specified time. (nodejs#4175)

Co-authored-by: Carlos Fuentes <me@metcoder.dev>
@github-actions github-actions bot mentioned this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants