-
Notifications
You must be signed in to change notification settings - Fork 490
Sync Dev from Master #1876
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
Merged
Sync Dev from Master #1876
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
**/packages | ||
**/launchSettings.json | ||
**/Debug/ | ||
**/build/ | ||
|
||
**/project.lock.json | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Threading.Tasks; | ||
namespace Amazon.Lambda.Core | ||
{ | ||
#if NET8_0_OR_GREATER | ||
/// <summary> | ||
/// Static class to register callback hooks to during the snapshot and restore phases of Lambda SnapStart. Hooks | ||
/// should be registered as part of the constructor of the type containing the function handler or before the | ||
/// `LambdaBootstrap` is started in executable assembly Lambda functions. | ||
/// </summary> | ||
public static class SnapshotRestore | ||
{ | ||
// We don't want Amazon.Lambda.Core to have any dependencies because the packaged handler code | ||
// that gets uploaded to AWS Lambda could have a version mismatch with the version that is already | ||
// included in the managed runtime. This class allows us to define a simple API that both the | ||
// RuntimeClient and handler code can use to register and then call these actions without | ||
// depending on a specific version of SnapshotRestore.Registry. | ||
private static readonly ConcurrentQueue<Func<ValueTask>> BeforeSnapshotRegistry = new(); | ||
private static readonly ConcurrentQueue<Func<ValueTask>> AfterRestoreRegistry = new(); | ||
|
||
internal static void CopyBeforeSnapshotCallbacksToRegistry(Action<Func<ValueTask>> restoreHooksRegistryMethod) | ||
{ | ||
// To preserve the order of registry, BeforeSnapshotRegistry in Core needs to be a Queue | ||
// These callbacks will be added to the Stack that SnapshotRestore.Registry maintains | ||
while (BeforeSnapshotRegistry.TryDequeue(out var registeredAction)) | ||
{ | ||
restoreHooksRegistryMethod?.Invoke(registeredAction); | ||
} | ||
} | ||
|
||
internal static void CopyAfterRestoreCallbacksToRegistry(Action<Func<ValueTask>> restoreHooksRegistryMethod) | ||
{ | ||
while (AfterRestoreRegistry.TryDequeue(out var registeredAction)) | ||
{ | ||
restoreHooksRegistryMethod?.Invoke(registeredAction); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Register callback hook to be called before Lambda creates a snapshot of the running process. This can be used to warm code in the .NET process or close connections before the snapshot is taken. | ||
/// </summary> | ||
/// <param name="beforeSnapshotAction"></param> | ||
public static void RegisterBeforeSnapshot(Func<ValueTask> beforeSnapshotAction) | ||
{ | ||
BeforeSnapshotRegistry.Enqueue(beforeSnapshotAction); | ||
} | ||
|
||
/// <summary> | ||
/// Register callback hook to be called after Lambda restores a snapshot of the running process. This can be used to ensure uniqueness after restoration. For example reseeding random number generators. | ||
/// </summary> | ||
/// <param name="afterRestoreAction"></param> | ||
public static void RegisterAfterRestore(Func<ValueTask> afterRestoreAction) | ||
{ | ||
AfterRestoreRegistry.Enqueue(afterRestoreAction); | ||
} | ||
} | ||
#endif | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't appear to terminate or exit the call which means it will fall through where registry will be null. The following comment says
no expection in calling SnapStart hooks
but it looks like there could have been an exception still. Is this correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct. We wanted to support users still enabling SnapStart without updating their version of Amazon.Lambda.Core. If they have an older version of Core in the deployment bundle we will get a
TypeLoadException
when we try to access the registry in it. It is the awkwardness of dependencies in Lambda.