Skip to content
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

Make ConnectionPool's retryConnectionEstablishment public #744

Merged
merged 8 commits into from
Jun 18, 2024
6 changes: 3 additions & 3 deletions Sources/AsyncHTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1025,16 +1025,16 @@ extension HTTPClient.Configuration {
/// - warning: We highly recommend leaving this on.
/// It is very common that connections establishment is flaky at scale.
/// ``HTTPClient`` will automatically mitigate these kind of issues if this flag is turned on.
var retryConnectionEstablishment: Bool
public var retryConnectionEstablishment: Bool

public init(idleTimeout: TimeAmount = .seconds(60)) {
self.init(idleTimeout: idleTimeout, concurrentHTTP1ConnectionsPerHostSoftLimit: 8)
}

public init(idleTimeout: TimeAmount, concurrentHTTP1ConnectionsPerHostSoftLimit: Int) {
public init(idleTimeout: TimeAmount, concurrentHTTP1ConnectionsPerHostSoftLimit: Int, retryConnectionEstablishment: Bool = true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately it's not API stable to add this extra parameter. Rather than us keep proliferating new inits, it might be nice for us to just add a zero-element initializer and encourage users towards setting the fields after default construction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look! I've...

  • Reverted the change to the existing initializer.
  • Added a parameterless initializer.
  • Removed the default value for the parameter idleTimeout in the respective initializer (because it overlaps with the new parameterless initializer). Is that safe in terms of API stability?
  • Moved the default values to the respective property declarations (to prevent them having to be specified at multiple points in the initializer code). This seems cleaner to me than initializer delegation, but if you prefer a different style, let me know.

self.idleTimeout = idleTimeout
self.concurrentHTTP1ConnectionsPerHostSoftLimit = concurrentHTTP1ConnectionsPerHostSoftLimit
self.retryConnectionEstablishment = true
self.retryConnectionEstablishment = retryConnectionEstablishment
}
}

Expand Down
15 changes: 6 additions & 9 deletions Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ class HTTPClientNIOTSTests: XCTestCase {
guard isTestingNIOTS() else { return }

let httpBin = HTTPBin(.http1_1(ssl: true))
var config = HTTPClient.Configuration()
config.networkFrameworkWaitForConnectivity = false
config.connectionPool.retryConnectionEstablishment = false
let config = HTTPClient.Configuration()
.enableFastFailureModeForTesting()
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: config)
defer {
Expand All @@ -84,9 +83,8 @@ class HTTPClientNIOTSTests: XCTestCase {
guard isTestingNIOTS() else { return }
#if canImport(Network)
let httpBin = HTTPBin(.http1_1(ssl: false))
var config = HTTPClient.Configuration()
config.networkFrameworkWaitForConnectivity = false
config.connectionPool.retryConnectionEstablishment = false
let config = HTTPClient.Configuration()
.enableFastFailureModeForTesting()

let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: config)
Expand Down Expand Up @@ -140,9 +138,8 @@ class HTTPClientNIOTSTests: XCTestCase {
tlsConfig.minimumTLSVersion = .tlsv11
tlsConfig.maximumTLSVersion = .tlsv1

var clientConfig = HTTPClient.Configuration(tlsConfiguration: tlsConfig)
clientConfig.networkFrameworkWaitForConnectivity = false
clientConfig.connectionPool.retryConnectionEstablishment = false
let clientConfig = HTTPClient.Configuration(tlsConfiguration: tlsConfig)
.enableFastFailureModeForTesting()
let httpClient = HTTPClient(
eventLoopGroupProvider: .shared(self.clientGroup),
configuration: clientConfig
Expand Down