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

Skip serialization of http result when it is stored in an output binding #2896

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore <version>

- <entry>
- Fix intermittent error `IFeatureCollection has been disposed` exception in multiple-output binding scenarios. (#2896)

### Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.Analyzers <version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Azure.Functions.Worker.Extensions.Http.Converters;
using Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.Infrastructure;
using Microsoft.Azure.Functions.Worker.Extensions.Http.Converters;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Azure.Functions.Worker.Middleware;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -85,6 +85,9 @@ private static async Task<bool> TryHandleHttpResult(object? result, FunctionCont
// processing is required.
context.GetInvocationResult().Value = null;
break;
case AspNetCoreHttpResponseData when !isInvocationResult:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should test for the base class - HttpResponseData instead? In theory, I could see a customer adding a middleware which will replace/wrap that input binding with their own. We would still want this to work in that case.

Now I am unsure if that scenario is possible with todays extension points. But unless we absolutely need the type to be exactly AspNetCoreHttpResponseData, it is typically better to work off the base class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above case for the invocation result also uses the more specific type (AspNetCoreHttpResponseData). The reasoning is captured here in another code review. I also had the same thought originally.

await TryClearHttpOutputBinding(context);
break;
case IResult iResult:
await iResult.ExecuteAsync(httpContext);
break;
Expand All @@ -105,6 +108,21 @@ private static Task<bool> TryHandleOutputBindingsHttpResult(FunctionContext cont
: TryHandleHttpResult(httpOutputBinding.Value, context, httpContext);
}

private static Task<bool> TryClearHttpOutputBinding(FunctionContext context)
{
var httpOutputBinding = context.GetOutputBindings<object>()
.FirstOrDefault(a => string.Equals(a.BindingType, HttpBindingType, StringComparison.OrdinalIgnoreCase));

if (httpOutputBinding is null)
{
return Task.FromResult(false);
}

httpOutputBinding.Value = null;

return Task.FromResult(true);
}

private static void AddHttpContextToFunctionContext(FunctionContext funcContext, HttpContext httpContext)
{
funcContext.Items.Add(Constants.HttpContextKey, httpContext);
Expand Down
Loading