Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] user can create multiple instances of the Lambda Runtime #507

Open
sebsto opened this issue Mar 14, 2025 · 1 comment
Open

[core] user can create multiple instances of the Lambda Runtime #507

sebsto opened this issue Mar 14, 2025 · 1 comment
Assignees
Labels
kind/bug Feature doesn't work as expected. 🆕 semver/minor Adds new public API.
Milestone

Comments

@sebsto
Copy link
Contributor

sebsto commented Mar 14, 2025

Now that user controls the main function with the runtime v2, nothing prevents users to create multiple runtimes.

I tested the code below on Lambda and it works. Any of the two runtimes can pickup the invocation and respond. In my exemple, they're booth taking the same input parameter and there is not too much consequences. But if the user codes the two handler with different input types, the Lambda function will crash when the "incorrect" runtime picks up the event.

We should enforce the runtime as a singleton.

demo code

import AWSLambdaRuntime

let runtime1 = LambdaRuntime {
    (event: String, context: LambdaContext) in
    "Hello1 \(event)"
}

let runtime2 = LambdaRuntime {
    (event: String, context: LambdaContext) in
    "Hello2 \(event)"
}

try await withThrowingTaskGroup(of: Void.self) { group in
    group.addTask {
        try await runtime1.run()
    }
    group.addTask {
        try await runtime2.run()
    }

    try await group.waitForAll()
}

@sebsto sebsto added kind/bug Feature doesn't work as expected. 🆕 semver/minor Adds new public API. labels Mar 14, 2025
@sebsto sebsto added this to the 2.0 milestone Mar 14, 2025
@sebsto sebsto self-assigned this Mar 14, 2025
@sebsto
Copy link
Contributor Author

sebsto commented Mar 14, 2025

I proposed a fix in this PR
#508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Feature doesn't work as expected. 🆕 semver/minor Adds new public API.
Projects
None yet
Development

No branches or pull requests

1 participant