From 77187dca253d57405d2a3f0596ab00d62a722b2d Mon Sep 17 00:00:00 2001 From: philip pittle Date: Mon, 12 May 2025 20:34:28 -0700 Subject: [PATCH 1/2] create unique feature collection on every warmup call and suppress and exception disposing the context (cherry picked from commit 7224bca5f8e6c95095daf4eed726fd02c7fad7f9) --- .../AbstractAspNetCoreFunction.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs b/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs index 27e09e7a6..a4041dd5f 100644 --- a/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs +++ b/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs @@ -1,4 +1,4 @@ -using Amazon.Lambda.AspNetCoreServer.Internal; +using Amazon.Lambda.AspNetCoreServer.Internal; using Amazon.Lambda.Core; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http.Features; @@ -318,16 +318,16 @@ private void AddRegisterBeforeSnapshot() var request = await HttpRequestMessageConverter.ConvertToLambdaRequest(httpRequest); - InvokeFeatures features = new InvokeFeatures(); - (features as IItemsFeature).Items = new Dictionary(); - (features as IServiceProvidersFeature).RequestServices = _hostServices; + for (var i = 0; i < invokeTimes; i++) + { + InvokeFeatures features = new InvokeFeatures(); + (features as IItemsFeature).Items = new Dictionary(); + (features as IServiceProvidersFeature).RequestServices = _hostServices; - MarshallRequest(features, request, new SnapStartEmptyLambdaContext()); + MarshallRequest(features, request, new SnapStartEmptyLambdaContext()); - var context = CreateContext(features); + var context = CreateContext(features); - for (var i = 0; i < invokeTimes; i++) - { var lambdaContext = new SnapStartEmptyLambdaContext(); await ProcessRequest(lambdaContext, context, features); From 71fd000d7daaef4cdd61ef8ae8f4e448f03319b0 Mon Sep 17 00:00:00 2001 From: philip pittle Date: Wed, 14 May 2025 12:44:22 -0700 Subject: [PATCH 2/2] add changelog message --- .../6ecba481-6957-4fd3-a562-dcf8676ab88c.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .autover/changes/6ecba481-6957-4fd3-a562-dcf8676ab88c.json diff --git a/.autover/changes/6ecba481-6957-4fd3-a562-dcf8676ab88c.json b/.autover/changes/6ecba481-6957-4fd3-a562-dcf8676ab88c.json new file mode 100644 index 000000000..4fd5856ad --- /dev/null +++ b/.autover/changes/6ecba481-6957-4fd3-a562-dcf8676ab88c.json @@ -0,0 +1,18 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.AspNetCoreServer", + "Type": "Patch", + "ChangelogMessages": [ + "Fixed issue when executing AddRegisterBeforeSnapshot callbacks to ensure each invocation has a new ASP.NET Core feature collection and HttpContext." + ] + }, + { + "Name": "Amazon.Lambda.AspNetCoreServer.Hosting", + "Type": "Patch", + "ChangelogMessages": [ + "Update Amazon.Lambda.AspNetCoreServer dependency for latest patch fix." + ] + } + ] +} \ No newline at end of file