mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-06-02 07:37:34 +00:00
Fix Connection Creation Crash (#873)
### Motivation When creating a connection, we wrongfully assumed that `failedToCreateNewConnection` will always be called before `http*ConnectionClosed` in the `HTTPConnectionPoolStateMachine`. However this is far from correct. In NIO Futures are fulfilled before `ChannelHandler` callbacks. Ordering in futures should not be assumed in such a complex project. ### Change We change the `http*ConnectionClosed` methods to be noops, if the connection is in the starting state. We instead wait for the `failedToCreateNewConnection` to create backoff timers and friends. rdar://164674912 --------- Co-authored-by: George Barnett <gbarnett@apple.com>
This commit is contained in:
co-authored by
George Barnett
parent
ce04df0613
commit
3c45dbde2d
+5
-4
@@ -250,6 +250,11 @@ extension HTTPConnectionPool {
|
||||
self.failedConsecutiveConnectionAttempts += 1
|
||||
self.lastConnectFailure = error
|
||||
|
||||
// We don't care how many waiting requests we have at this point, we will schedule a
|
||||
// retry. More tasks, may appear until the backoff has completed. The final
|
||||
// decision about the retry will be made in `connectionCreationBackoffDone(_:)`
|
||||
let eventLoop = self.connections.backoffNextConnectionAttempt(connectionID)
|
||||
|
||||
switch self.lifecycleState {
|
||||
case .running:
|
||||
guard self.retryConnectionEstablishment else {
|
||||
@@ -265,10 +270,6 @@ extension HTTPConnectionPool {
|
||||
connection: .none
|
||||
)
|
||||
}
|
||||
// We don't care how many waiting requests we have at this point, we will schedule a
|
||||
// retry. More tasks, may appear until the backoff has completed. The final
|
||||
// decision about the retry will be made in `connectionCreationBackoffDone(_:)`
|
||||
let eventLoop = self.connections.backoffNextConnectionAttempt(connectionID)
|
||||
|
||||
let backoff = calculateBackoff(failedAttempt: self.failedConsecutiveConnectionAttempts)
|
||||
return .init(
|
||||
|
||||
Reference in New Issue
Block a user