Skip to content

Weakly capture the HTTPConnectionPool in the idle connection timeout task #853

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

Closed
wants to merge 1 commit into from

Conversation

ahoppen
Copy link

@ahoppen ahoppen commented Aug 18, 2025

Currently, the HTTPConnectionPool will be kept alive until the idle connection timeout has fired. I don’t see a reason to keep the HTTPConnectionPool around if the idle connection timeout future is the only thing that’s still referencing the HTTPConnectionPool.

…t task

Currently, the `HTTPConnectionPool` will be kept alive until the idle connection timeout has fired. I don’t see a reason to keep the `HTTPConnectionPool` around if the idle connection timeout future is the only thing that’s still referencing the `HTTPConnectionPool`.
@@ -394,7 +394,10 @@ final class HTTPConnectionPool:
"ahc-connection-id": "\(connectionID)"
]
)
let scheduled = eventLoop.scheduleTask(in: self.idleConnectionTimeout) {
let scheduled = eventLoop.scheduleTask(in: self.idleConnectionTimeout) { [weak self] in
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should avoid the use of a weak reference here: its performance impact will be very substantial.

Instead, so long as all of these tasks are cancelled in the shutdown routine (as they should be), there will be no leak, as the cancellation of the tasks will drop the function reference.

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Let’s avoid weak references.

@ahoppen ahoppen closed this Aug 18, 2025
@ahoppen
Copy link
Author

ahoppen commented Aug 18, 2025

OK, gotcha. The case where I hit this has changed slightly so that this is no longer relevant for me, so I won’t be putting any more work into this PR.

@ahoppen ahoppen deleted the weak-connection-timeout branch August 18, 2025 19:55
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.

2 participants