Skip to content

Commit be91678

Browse files
committed
Remove isShutdown
1 parent 2b2b0e5 commit be91678

File tree

4 files changed

+28
-39
lines changed

4 files changed

+28
-39
lines changed

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ final class HTTPConnectionPool:
108108
case closeConnectionAndCreateConnection(
109109
close: Connection,
110110
newConnectionID: Connection.ID,
111-
on: EventLoop,
112-
isShutdown: StateMachine.ConnectionAction.IsShutdown
111+
on: EventLoop
113112
)
114113
case cleanupConnections(CleanupContext, isShutdown: StateMachine.ConnectionAction.IsShutdown)
115114
case migration(
@@ -204,15 +203,13 @@ final class HTTPConnectionPool:
204203
self.unlocked.connection = .closeConnection(connection, isShutdown: isShutdown)
205204
case .closeConnectionAndCreateConnection(
206205
let closeConnection,
207-
let isShutdown,
208206
let newConnectionID,
209207
let eventLoop
210208
):
211209
self.unlocked.connection = .closeConnectionAndCreateConnection(
212210
close: closeConnection,
213211
newConnectionID: newConnectionID,
214-
on: eventLoop,
215-
isShutdown: isShutdown
212+
on: eventLoop
216213
)
217214
case .cleanupConnections(var cleanupContext, let isShutdown):
218215
self.locked.connection = .cancelBackoffTimers(cleanupContext.connectBackoff)
@@ -314,8 +311,7 @@ final class HTTPConnectionPool:
314311
case .closeConnectionAndCreateConnection(
315312
let connectionToClose,
316313
let newConnectionID,
317-
let eventLoop,
318-
let isShutdown
314+
let eventLoop
319315
):
320316
self.logger.trace(
321317
"closing and creating connection",
@@ -324,19 +320,11 @@ final class HTTPConnectionPool:
324320
]
325321
)
326322

327-
// If the pool is shutdown, let's just not create this new connection.
328-
if case .no = isShutdown {
329-
self.createConnection(newConnectionID, on: eventLoop)
330-
}
323+
self.createConnection(newConnectionID, on: eventLoop)
331324

332325
// we are not interested in the close promise...
333326
connectionToClose.close(promise: nil)
334327

335-
// This isn't really reachable.
336-
if case .yes(let unclean) = isShutdown {
337-
self.delegate.connectionPoolDidShutdown(self, unclean: unclean)
338-
}
339-
340328
case .cleanupConnections(let cleanupContext, let isShutdown):
341329
for connection in cleanupContext.close {
342330
connection.close(promise: nil)

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP1StateMachine.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ extension HTTPConnectionPool {
579579
let newConnectionID = self.connections.createNewConnection(on: connectionToClose.eventLoop)
580580
connectionAction = .closeConnectionAndCreateConnection(
581581
closeConnection: connectionToClose,
582-
isShutdown: .no,
583582
newConnectionID: newConnectionID,
584583
on: connectionToClose.eventLoop
585584
)

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+StateMachine.swift

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ extension HTTPConnectionPool {
5757
case cleanupConnections(CleanupContext, isShutdown: IsShutdown)
5858
case closeConnectionAndCreateConnection(
5959
closeConnection: Connection,
60-
isShutdown: IsShutdown,
6160
newConnectionID: Connection.ID,
6261
on: EventLoop
6362
)
@@ -441,7 +440,6 @@ extension HTTPConnectionPool.StateMachine {
441440
)
442441
case closeConnectionAndCreateConnection(
443442
closeConnection: HTTPConnectionPool.Connection,
444-
isShutdown: HTTPConnectionPool.StateMachine.ConnectionAction.IsShutdown,
445443
newConnectionID: HTTPConnectionPool.Connection.ID,
446444
on: EventLoop
447445
)
@@ -472,13 +470,11 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction {
472470
self = .closeConnection(connection, isShutdown: isShutdown)
473471
case .closeConnectionAndCreateConnection(
474472
let closeConnection,
475-
let isShutdown,
476473
let newConnectionID,
477474
let eventLoop
478475
):
479476
self = .closeConnectionAndCreateConnection(
480477
closeConnection: closeConnection,
481-
isShutdown: isShutdown,
482478
newConnectionID: newConnectionID,
483479
on: eventLoop
484480
)
@@ -510,28 +506,14 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction {
510506
)
511507
case .closeConnectionAndCreateConnection(
512508
closeConnection: let connection,
513-
let isShutdown,
514509
newConnectionID: _,
515510
on: _
516511
):
517512
// This event can only come _from_ the HTTP/1 pool, migrating to HTTP/2. We do not do prewarmed HTTP/2 connections,
518513
// so we can ignore the request for a new connection. This is thus the same as the case below.
519-
fallthrough
514+
return Self.closeConnection(connection, isShutdown: .no, migrationAction: migrationAction)
520515
case .closeConnection(let connection, let isShutdown):
521-
guard isShutdown == .no else {
522-
precondition(
523-
migrationAction.closeConnections.isEmpty && migrationAction.createConnections.isEmpty,
524-
"migration actions are not supported during shutdown"
525-
)
526-
return .closeConnection(connection, isShutdown: isShutdown)
527-
}
528-
var closeConnections = migrationAction.closeConnections
529-
closeConnections.append(connection)
530-
return .migration(
531-
createConnections: migrationAction.createConnections,
532-
closeConnections: closeConnections,
533-
scheduleTimeout: nil
534-
)
516+
return Self.closeConnection(connection, isShutdown: isShutdown, migrationAction: migrationAction)
535517
case .scheduleTimeoutTimerAndCreateConnection(
536518
timeoutID: let connectionID,
537519
newConnectionID: _,
@@ -548,4 +530,25 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction {
548530
)
549531
}
550532
}
533+
534+
private static func closeConnection(
535+
_ connection: HTTPConnectionPool.Connection,
536+
isShutdown: HTTPConnectionPool.StateMachine.ConnectionAction.IsShutdown,
537+
migrationAction: HTTPConnectionPool.StateMachine.ConnectionMigrationAction
538+
) -> Self {
539+
guard isShutdown == .no else {
540+
precondition(
541+
migrationAction.closeConnections.isEmpty && migrationAction.createConnections.isEmpty,
542+
"migration actions are not supported during shutdown"
543+
)
544+
return .closeConnection(connection, isShutdown: isShutdown)
545+
}
546+
var closeConnections = migrationAction.closeConnections
547+
closeConnections.append(connection)
548+
return .migration(
549+
createConnections: migrationAction.createConnections,
550+
closeConnections: closeConnections,
551+
scheduleTimeout: nil
552+
)
553+
}
551554
}

Tests/AsyncHTTPClientTests/HTTPConnectionPool+HTTP1StateTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,11 +1486,10 @@ class HTTPConnectionPool_HTTP1StateMachineTests: XCTestCase {
14861486

14871487
// Here the state machine has asked us to close the connection and create a new one. That's because we've hit the
14881488
// max usages limit.
1489-
guard case .closeConnectionAndCreateConnection(let toClose, let isShutdown, _, _) = action.connection else {
1489+
guard case .closeConnectionAndCreateConnection(let toClose, _, _) = action.connection else {
14901490
return XCTFail("Unexpected action: \(action.connection)")
14911491
}
14921492
try connections.closeConnection(toClose)
1493-
XCTAssertEqual(isShutdown, .no)
14941493

14951494
// We won't bother doing it though, it's enough that it asked.
14961495
}

0 commit comments

Comments
 (0)