swift-aws-lambda-runtime icon indicating copy to clipboard operation
swift-aws-lambda-runtime copied to clipboard

[core] Only one `LambdaRuntime.run()` can be called at a time (fix #507)

Open sebsto opened this issue 8 months ago • 4 comments

This is a proposal to fix issue #507

changes

  • LambdaRuntime.init() uses a Mutex<Bool> to make sure only one instance is created
  • LambdaRuntime.init() can now throw an error in case an instance already exists (I did not use fatalError() to make it easier to test)
  • All convenience init() methods catch possible errors instead of re-throwing it to a void breaking the user-facing API
  • Renamed existing LambdaRuntimeError to LambdaRuntimeClientError
  • Introduced a new type LambdaRuntimeError to represent the double initialization error

sebsto avatar Mar 14 '25 12:03 sebsto

Compiler crashes on nightly build has been reported here https://github.com/swiftlang/swift/issues/80020

sebsto avatar Mar 14 '25 17:03 sebsto

CI is now green, except API Breakage, which is expected.

sebsto avatar Mar 15 '25 09:03 sebsto

@fabianfett I changed

  • Mutex for Atomic
  • Test is now on run() and not on init()
  • LamabdaRuntimeError returned and is now public + one additional error case
  • unit test is adjusted and pass

sebsto avatar Mar 19 '25 19:03 sebsto

Now that managing cancellation is working (thank you @adam https://github.com/swift-server/swift-aws-lambda-runtime/commit/b2811a5e1a96a98033ad857d9f93ff086dbba142)

This PR is ready to review before merged. API Breakage is expected as we are adding an error case.

sebsto avatar Jun 29 '25 12:06 sebsto