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

LambdaBootstrap no longer throws if initialization fails when not using SnapStart #1881

Closed
1 task done
martincostello opened this issue Nov 25, 2024 · 5 comments
Closed
1 task done
Labels
bug This issue is a bug. module/lambda-client-lib needs-review p2 This is a standard priority issue potential-regression Marking this issue as a potential regression to be checked by team member

Comments

@martincostello
Copy link
Contributor

Describe the bug

In my MartinCostello.Testing.AwsLambdaTestServer library I have a test that verifies that an exception is thrown if a function fails to startup.

With the changes to enable SnapStart in #1876 this appears to no longer occur an instead RunAsync() just runs to completion with no obvious sign of failure.

Is this an intentional behaviour change? It seems like an oversight to me as with SnapStart enabled the code will terminate the process:

#if NET8_0_OR_GREATER
if (_configuration.IsInitTypeSnapstart)
{
System.Environment.Exit(1); // This needs to be non-zero for Lambda Sandbox to know that Runtime client encountered an exception
}
#endif

But without, it will return false and then just return:

if (_initializer != null && !(await InitializeAsync()))
{
return;
}

As an aside, Environment.Exit(1) isn't great from a testability perspective (IMHO) as if IsInitTypeSnapstart was true in my test, it would terminate the test process.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

An exception is thrown.

Current Behavior

LambdaBootstrap.RunAsync() returns with no error without invoking the lambda function.

Reproduction Steps

  1. Clone martincostello/lambda-test-server@b71e148
  2. Run build.ps1 from the root of the cloned repository.

Possible Solution

Preserve the original behaviour by throwing in the catch block if IsInitTypeSnapstart is false.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Amazon.Lambda.RuntimeSupport 1.12.0

Targeted .NET Platform

.NET 9

Operating System and version

Any

@martincostello martincostello added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 25, 2024
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Nov 25, 2024
@normj
Copy link
Member

normj commented Nov 25, 2024

This was intentional change for when this was running in SnapStart. Due to an upstream issue we needed to force an exit quickly otherwise we weren't getting the logs correctly sent to the Lambda service. We are hoping for an upstream change so we can get rid of the Environment.Exit call. I don't like calling Environment.Exit either.

The non SnapStart behavior change was a side effect of diagnosing the log issue. I'll revert the behavior so that in non SnapStart case if there was an error to let the exception bubble up.

@ashishdhingra ashishdhingra added needs-review p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 25, 2024
@normj
Copy link
Member

normj commented Nov 26, 2024

Version 1.12.1 of Amazon.Lambda.RuntimeSupport was released that reverts back the behavior for non SnapStart situation.

@martincostello
Copy link
Contributor Author

Thanks Norm - that went straight through with no issues: martincostello/lambda-test-server#823

@normj
Copy link
Member

normj commented Nov 27, 2024

Great! Thanks for letting us know the change was successful.

@normj normj closed this as completed Nov 27, 2024
Copy link
Contributor

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/lambda-client-lib needs-review p2 This is a standard priority issue potential-regression Marking this issue as a potential regression to be checked by team member
Projects
None yet
Development

No branches or pull requests

3 participants