@@ -177,12 +177,9 @@ final class ConnectionPool {
177
177
self . parentPool. release ( self )
178
178
}
179
179
180
- fileprivate func close( runCloseCallback: Bool = true ) -> EventLoopFuture < Void > {
181
- return self . channel. eventLoop. flatSubmit {
182
- self . shouldRunCloseCallback = runCloseCallback
183
- self . channel. close ( promise: nil )
184
- return self . closeFuture
185
- }
180
+ func close( ) -> EventLoopFuture < Void > {
181
+ self . channel. close ( promise: nil )
182
+ return self . closeFuture
186
183
}
187
184
188
185
var description : String {
@@ -213,7 +210,11 @@ final class ConnectionPool {
213
210
/// Indicates that this connection is about to close
214
211
var isClosing : Bool = false
215
212
216
- fileprivate var shouldRunCloseCallback : Bool = true
213
+ /// Indicates wether the usual close callback should be run or not, this allows customizing what happens
214
+ /// on close in some cases such as for the `.replaceConnection` action
215
+ ///
216
+ /// - Warning: This should be accessed under the `stateLock` of `HTTP1ConnectionProvider`
217
+ fileprivate var mustRunDefaultCloseCallback : Bool = true
217
218
218
219
/// Convenience property indicating wether the underlying `Channel` is active or not
219
220
var isActiveEstimation : Bool {
@@ -314,7 +315,7 @@ final class ConnectionPool {
314
315
self . makeConnection ( on: eventLoop) . cascade ( to: promise)
315
316
316
317
case . replaceConnection( let eventLoop, let promise) :
317
- connection. close ( runCloseCallback : false ) . flatMap {
318
+ connection. close ( ) . flatMap {
318
319
self . makeConnection ( on: eventLoop)
319
320
} . whenComplete { result in
320
321
switch result {
@@ -382,7 +383,7 @@ final class ConnectionPool {
382
383
connection. channel. closeFuture. whenComplete { result in
383
384
let action : HTTP1ConnectionProvider . State . ClosedConnectionRemoveAction ? = self . parentPool. connectionProvidersLock. withLock {
384
385
self . stateLock. withLock {
385
- guard connection. shouldRunCloseCallback else {
386
+ guard connection. mustRunDefaultCloseCallback else {
386
387
return nil
387
388
}
388
389
switch result {
@@ -420,7 +421,7 @@ final class ConnectionPool {
420
421
let waitersPromises = waitersCopy. map { $0. promise }
421
422
let waitersFutures = waitersPromises. map { $0. futureResult }
422
423
waitersPromises. forEach { $0. fail ( HTTPClientError . cancelled) }
423
- let closeFutures = self . state. availableConnections. map { $0. channel . close ( ) }
424
+ let closeFutures = self . state. availableConnections. map { $0. close ( ) }
424
425
return ( waitersFutures, closeFutures)
425
426
}
426
427
try ? EventLoopFuture < Connection > . andAllComplete ( waitersFutures, on: self . eventLoop) . wait ( )
@@ -524,6 +525,7 @@ final class ConnectionPool {
524
525
return . succeed( firstWaiter. promise)
525
526
} else {
526
527
if requiresSpecifiedEL {
528
+ connection. mustRunDefaultCloseCallback = false
527
529
return . replaceConnection( channelEL, firstWaiter. promise)
528
530
} else {
529
531
return . makeConnectionAndComplete( channelEL, firstWaiter. promise)
0 commit comments