Skip to content

Commit 61c05b6

Browse files
authored
Improve AddRegisterBeforeSnapshot (#2071)
* create unique feature collection on every warmup call and suppress and exception disposing the context (cherry picked from commit 7224bca5f8e6c95095daf4eed726fd02c7fad7f9) * add changelog message
1 parent 42820a6 commit 61c05b6

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.AspNetCoreServer",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Fixed issue when executing AddRegisterBeforeSnapshot callbacks to ensure each invocation has a new ASP.NET Core feature collection and HttpContext."
8+
]
9+
},
10+
{
11+
"Name": "Amazon.Lambda.AspNetCoreServer.Hosting",
12+
"Type": "Patch",
13+
"ChangelogMessages": [
14+
"Update Amazon.Lambda.AspNetCoreServer dependency for latest patch fix."
15+
]
16+
}
17+
]
18+
}

Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Amazon.Lambda.AspNetCoreServer.Internal;
1+
using Amazon.Lambda.AspNetCoreServer.Internal;
22
using Amazon.Lambda.Core;
33
using Microsoft.AspNetCore.Hosting;
44
using Microsoft.AspNetCore.Http.Features;
@@ -318,16 +318,16 @@ private void AddRegisterBeforeSnapshot()
318318

319319
var request = await HttpRequestMessageConverter.ConvertToLambdaRequest<TREQUEST>(httpRequest);
320320

321-
InvokeFeatures features = new InvokeFeatures();
322-
(features as IItemsFeature).Items = new Dictionary<object, object>();
323-
(features as IServiceProvidersFeature).RequestServices = _hostServices;
321+
for (var i = 0; i < invokeTimes; i++)
322+
{
323+
InvokeFeatures features = new InvokeFeatures();
324+
(features as IItemsFeature).Items = new Dictionary<object, object>();
325+
(features as IServiceProvidersFeature).RequestServices = _hostServices;
324326

325-
MarshallRequest(features, request, new SnapStartEmptyLambdaContext());
327+
MarshallRequest(features, request, new SnapStartEmptyLambdaContext());
326328

327-
var context = CreateContext(features);
329+
var context = CreateContext(features);
328330

329-
for (var i = 0; i < invokeTimes; i++)
330-
{
331331
var lambdaContext = new SnapStartEmptyLambdaContext();
332332

333333
await ProcessRequest(lambdaContext, context, features);

0 commit comments

Comments
 (0)