swift-aws-lambda-runtime
swift-aws-lambda-runtime copied to clipboard
Add support swift-service-lifecycle
The code on the main branch currently does not support Swift Service Lifecycle.
We started the implementation with these two PR
- #459 : make
LambdaRuntimeClient.nextInvocation()cancellable - #456 : Add
LambdaRuntimServiceand an example function
These two PR have unresolved issues.
- #459 is not Swift 6 compliant
/swift/lambda/swift-aws-lambda-runtime/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift:343:38: warning: sending 'handler' risks causing data races; this is an error in the Swift 6 language mode
341 | defer {
342 | for continuation in array {
343 | continuation.resume(returning: handler)
| |- warning: sending 'handler' risks causing data races; this is an error in the Swift 6 language mode
| `- note: 'self'-isolated 'handler' is passed as a 'sending' parameter; Uses in callee may race with later 'self'-isolated uses
344 | }
345 | }
- #456 adds partial support for graceful shutdown. But the graceful shutdown flag is not propagated down to the LambdaRuntimeClient. Currently, this call cannot be interrupted when a graceful shutdown is requested.
Do we want to use package traits here?
https://github.com/swiftlang/swift-evolution/blob/main/proposals/0450-swiftpm-package-traits.md
cc @FranzBusch
I think we landed this with #490. @sebsto close this one?
A big part has been landed yes. Not all of it. I’ll keep this for the example and the actual structure that implements the Service protocol
The missing part is graceful shutdown support?
We need to add
- an example
- create an extension of
LambdaRuntimethat implementsServiceprotocol - and check what happens in case of graceful shutdown.
Points 1. and 2. are in the PR I closed and I will submit a separate PR for these.
IMHO, when the LambdaRuntimeClient waits on /next, the only way to stop it is to cancel the Tasks. Therefore, graceful shutdown is very similar to task cancellation.
Ideally, we must be sure than any in flight user handler has the time to return a response. But the Lambda service will take care to re-create a runtime environment if one fails to return a response or error. So in this specific context, it is not that important to cleanly shutdown.
create an extension of
LambdaRuntimethat implementsServiceprotocol
https://github.com/swift-server/swift-aws-lambda-runtime/blob/bf02bcec9a22c060234ee9e417d36519eda6a572/Sources/AWSLambdaRuntime/LambdaRuntime%2BServiceLifecycle.swift#L18
Excellent I missed it. Thank you
Complete