Skip to content

Commit 38c53d0

Browse files
authored
fix: changes to fix lifetime issues when multiple sdks are in use (#390)
1 parent 2e36dab commit 38c53d0

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Packages/ClientRuntime/Sources/Networking/Http/CRT/CRTClientEngine.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class CRTClientEngine: HttpClientEngine {
2121

2222
private let windowSize: Int
2323
private let maxConnectionsPerEndpoint: Int
24+
private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared
2425

2526
init(config: CRTClientEngineConfig = CRTClientEngineConfig()) {
2627
self.maxConnectionsPerEndpoint = config.maxConnectionsPerEndpoint
@@ -147,8 +148,4 @@ public class CRTClientEngine: HttpClientEngine {
147148

148149
return (requestOptions, future)
149150
}
150-
151-
deinit {
152-
AwsCommonRuntimeKit.cleanUp()
153-
}
154151
}

Packages/ClientRuntime/Sources/Networking/Http/CRT/SDKDefaultIO.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ import AwsCommonRuntimeKit
99
import class Foundation.ProcessInfo
1010

1111
public final class SDKDefaultIO {
12-
public static let shared = SDKDefaultIO()
12+
static weak var privateShared: SDKDefaultIO? = nil
1313

14-
public let eventLoopGroup: EventLoopGroup
15-
public let hostResolver: DefaultHostResolver
16-
public let clientBootstrap: ClientBootstrap
17-
public let tlsContext: TlsContext
14+
// TODO: revisit this and verify that it is thread safe.
15+
public static var shared: SDKDefaultIO {
16+
if let shared = privateShared {
17+
return shared
18+
} else {
19+
let shared = SDKDefaultIO()
20+
privateShared = shared
21+
return shared
22+
}
23+
}
24+
25+
public var eventLoopGroup: EventLoopGroup
26+
public var hostResolver: DefaultHostResolver
27+
public var clientBootstrap: ClientBootstrap
28+
public var tlsContext: TlsContext
1829

1930
private init() {
2031
AwsCommonRuntimeKit.initialize()

Packages/ClientRuntime/Sources/Retries/SDKRetryer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import AwsCommonRuntimeKit
88

99
public class SDKRetryer: Retryer {
1010
let crtRetryStrategy: CRTAWSRetryStrategy
11+
private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared
1112

1213
public init(options: RetryOptions) throws {
1314
self.crtRetryStrategy = try CRTAWSRetryStrategy(options: options.toCRTType())

0 commit comments

Comments
 (0)