Skip to content

Commit 05a087e

Browse files
committed
make explicit that we ignore ChannelError I/O on closed channel during shutdown
1 parent 31edfb0 commit 05a087e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Sources/AWSLambdaRuntime/Lambda+LocalServer.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,21 @@ extension Lambda {
5151
logger: Logger,
5252
_ body: sending @escaping () async throws -> Void
5353
) 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)")
5969
}
6070
}
6171
}
@@ -106,7 +116,7 @@ internal struct LambdaHTTPServer {
106116
eventLoopGroup: MultiThreadedEventLoopGroup = .singleton,
107117
logger: Logger,
108118
_ closure: sending @escaping () async throws -> Result
109-
) async throws -> Swift.Result<Result, any Error> {
119+
) async throws -> Result {
110120
let channel = try await ServerBootstrap(group: eventLoopGroup)
111121
.serverChannelOption(.backlog, value: 256)
112122
.serverChannelOption(.socketOption(.so_reuseaddr), value: 1)
@@ -227,7 +237,7 @@ internal struct LambdaHTTPServer {
227237
if case .failure(let error) = result {
228238
logger.error("Error during server shutdown: \(error)")
229239
}
230-
return result
240+
return try result.get()
231241
}
232242

233243
/// This method handles individual TCP connections

0 commit comments

Comments
 (0)