From e4fa22e04f3dbc45520c3cb5b5b7f76401b3dacd Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Mon, 18 Aug 2025 15:44:21 +0200 Subject: [PATCH] Weakly capture the `HTTPConnectionPool` in the idle connection timeout task MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- .../AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift b/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift index 251224ac0..65094a592 100644 --- a/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift +++ b/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift @@ -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 + guard let self else { + return + } // there might be a race between a cancelTimer call and the triggering // of this scheduled task. both want to acquire the lock self.modifyStateAndRunActions { stateMachine in