@@ -114,6 +114,8 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
114
114
}
115
115
116
116
private func close( ) async {
117
+ self . logger. trace ( " Close lambda runtime client " )
118
+
117
119
guard case . notClosing = self . closingState else {
118
120
return
119
121
}
@@ -229,10 +231,24 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
229
231
230
232
private func channelClosed( _ channel: any Channel ) {
231
233
switch ( self . connectionState, self . closingState) {
232
- case ( . disconnected, _) ,
233
- ( _, . closed) :
234
+ case ( _, . closed) :
234
235
fatalError ( " Invalid state: \( self . connectionState) , \( self . closingState) " )
235
236
237
+ case ( . disconnected, . notClosing) :
238
+ if let index = self . closingConnections. firstIndex ( where: { $0 === channel } ) {
239
+ self . closingConnections. remove ( at: index)
240
+ }
241
+
242
+ case ( . disconnected, . closing( let continuation) ) :
243
+ if let index = self . closingConnections. firstIndex ( where: { $0 === channel } ) {
244
+ self . closingConnections. remove ( at: index)
245
+ }
246
+
247
+ if self . closingConnections. isEmpty {
248
+ self . closingState = . closed
249
+ continuation. resume ( )
250
+ }
251
+
236
252
case ( . connecting( let array) , . notClosing) :
237
253
self . connectionState = . disconnected
238
254
for continuation in array {
@@ -303,8 +319,14 @@ final actor NewLambdaRuntimeClient: LambdaRuntimeClientProtocol {
303
319
let handler = try channel. pipeline. syncOperations. handler (
304
320
type: LambdaChannelHandler< NewLambdaRuntimeClient> . self
305
321
)
322
+ self . logger. trace (
323
+ " Connection to control plane created " ,
324
+ metadata: [
325
+ " lambda_port " : " \( self . configuration. port) " ,
326
+ " lambda_ip " : " \( self . configuration. ip) " ,
327
+ ]
328
+ )
306
329
channel. closeFuture. whenComplete { result in
307
- self . eventLoop. preconditionInEventLoop ( )
308
330
self . assumeIsolated { runtimeClient in
309
331
runtimeClient. channelClosed ( channel)
310
332
}
@@ -754,6 +776,12 @@ extension LambdaChannelHandler: ChannelInboundHandler {
754
776
}
755
777
756
778
func errorCaught( context: ChannelHandlerContext , error: Error ) {
779
+ self . logger. trace (
780
+ " Channel error caught " ,
781
+ metadata: [
782
+ " error " : " \( error) "
783
+ ]
784
+ )
757
785
// pending responses will fail with lastError in channelInactive since we are calling context.close
758
786
self . delegate. connectionErrorHappened ( error, channel: context. channel)
759
787
0 commit comments