@@ -51,11 +51,21 @@ extension Lambda {
51
51
logger: Logger ,
52
52
_ body: sending @escaping ( ) async throws -> Void
53
53
) async throws {
54
- _ = try await LambdaHTTPServer . withLocalServer (
55
- invocationEndpoint: invocationEndpoint,
56
- logger: logger
57
- ) {
58
- try await body ( )
54
+ do {
55
+ try await LambdaHTTPServer . withLocalServer (
56
+ invocationEndpoint: invocationEndpoint,
57
+ logger: logger
58
+ ) {
59
+ try await body ( )
60
+ }
61
+ } catch let error as ChannelError {
62
+ // when this server is part of a ServiceLifeCycle group
63
+ // and user presses CTRL-C, this error is thrown
64
+ // The error description is "I/O on closed channel"
65
+ // TODO: investigate and solve the root cause
66
+ // because this server is used only for local tests
67
+ // and the error happens when we shutdown the server, I decided to ignore it at the moment.
68
+ logger. trace ( " Ignoring ChannelError during local server shutdown: \( error) " )
59
69
}
60
70
}
61
71
}
@@ -106,7 +116,7 @@ internal struct LambdaHTTPServer {
106
116
eventLoopGroup: MultiThreadedEventLoopGroup = . singleton,
107
117
logger: Logger ,
108
118
_ closure: sending @escaping ( ) async throws -> Result
109
- ) async throws -> Swift . Result < Result , any Error > {
119
+ ) async throws -> Result {
110
120
let channel = try await ServerBootstrap ( group: eventLoopGroup)
111
121
. serverChannelOption ( . backlog, value: 256 )
112
122
. serverChannelOption ( . socketOption( . so_reuseaddr) , value: 1 )
@@ -227,7 +237,7 @@ internal struct LambdaHTTPServer {
227
237
if case . failure( let error) = result {
228
238
logger. error ( " Error during server shutdown: \( error) " )
229
239
}
230
- return result
240
+ return try result. get ( )
231
241
}
232
242
233
243
/// This method handles individual TCP connections
0 commit comments