Skip to content

Commit 02ed4e8

Browse files
committed
Fix after rebase
1 parent 0eede83 commit 02ed4e8

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

Sources/AWSLambdaRuntimeCore/NewLambdaRuntimeClient.swift

+29-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
2525
var port: Int
2626
}
2727

28-
struct Writer: LambdaResponseStreamWriter {
28+
struct Writer: LambdaRuntimeClientResponseStreamWriter {
2929
private var runtimeClient: NewLambdaRuntimeClient
3030

3131
fileprivate init(runtimeClient: NewLambdaRuntimeClient) {
@@ -71,6 +71,7 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
7171
enum ClosingState {
7272
case notClosing
7373
case closing(CheckedContinuation<Void, Never>)
74+
case closed
7475
}
7576

7677
private let eventLoop: any EventLoop
@@ -121,20 +122,20 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
121122

122123
switch self.connectionState {
123124
case .disconnected:
124-
break
125+
if self.closingConnections.isEmpty {
126+
return continuation.resume()
127+
}
125128

126129
case .connecting(let continuations):
127130
for continuation in continuations {
128131
continuation.resume(throwing: NewLambdaRuntimeError(code: .closingRuntimeClient))
129132
}
130133
self.connectionState = .connecting([])
131134

132-
case .connected(let channel, let lambdaChannelHandler):
133-
channel.clo
135+
case .connected(let channel, _):
136+
channel.close(mode: .all, promise: nil)
134137
}
135138
}
136-
137-
138139
}
139140

140141
func nextInvocation() async throws -> (Invocation, Writer) {
@@ -227,19 +228,35 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
227228
}
228229

229230
private func channelClosed(_ channel: any Channel) {
230-
switch self.connectionState {
231-
case .disconnected:
232-
break
231+
switch (self.connectionState, self.closingState) {
232+
case (.disconnected, _),
233+
(_, .closed):
234+
fatalError("Invalid state: \(self.connectionState), \(self.closingState)")
233235

234-
case .connecting(let array):
236+
case (.connecting(let array), .notClosing):
235237
self.connectionState = .disconnected
236-
237238
for continuation in array {
238239
continuation.resume(throwing: NewLambdaRuntimeError(code: .lostConnectionToControlPlane))
239240
}
240241

241-
case .connected:
242+
case (.connecting(let array), .closing(let continuation)):
243+
self.connectionState = .disconnected
244+
precondition(array.isEmpty, "If we are closing we should have failed all connection attempts already")
245+
if self.closingConnections.isEmpty {
246+
self.closingState = .closed
247+
continuation.resume()
248+
}
249+
250+
case (.connected, .notClosing):
251+
self.connectionState = .disconnected
252+
253+
case (.connected, .closing(let continuation)):
242254
self.connectionState = .disconnected
255+
256+
if self.closingConnections.isEmpty {
257+
self.closingState = .closed
258+
continuation.resume()
259+
}
243260
}
244261
}
245262

@@ -356,7 +373,6 @@ extension NewLambdaRuntimeClient: LambdaChannelHandlerDelegate {
356373

357374
isolated.connectionState = .disconnected
358375

359-
360376
}
361377
}
362378

0 commit comments

Comments
 (0)