Reputation: 1
I used an HTTP trigger to trigger an Azure function. My request body is only around 30MB, and the URL Length is below 4KB. The function still runs normally but when returning a response or throwing an exception. I will get the Error and never receive a response (always status code 500). If the body size is around or less than 25MB, the function works normally and still receives a response.
This is error message:
Failed to proxy request to the worker. Retrying in 50ms. Attempt 1 of 3. Failed to proxy request to the worker. Retrying in 100ms. Attempt 2 of 3. System.Private.CoreLib: Exception while executing function: Functions.function-name. Microsoft.Azure.WebJobs.Script.Grpc: Failed to proxy request with ForwarderError: RequestBodyDestination. One or more er rors occurred. (Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..) (An error occurred while sending the request.). System.Net.Sockets: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.. An existing connection was forcibly closed by the remote host.
I want to be able to handle requests with a body size of less than 100MB, as per the Azure Function documentation, without encountering errors like this anymore.
Upvotes: 0
Views: 658
Reputation: 6497
The error is populating when you are using ASP .NET Core Integration in Isolated function which is to have ConfigureFunctionsWebApplication() and its related packages in program.cs and .csproj file respectively.
Azure Isolated Function comes with or without integration. If you are comfortable to use Isolated Azure Function without the ASP .NET core integration then use ConfigureFunctionsWorkerDefaults(). You should have given code in program.cs file.
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.Build();
host.Run();
To support this, you should have given packages in .csproj file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>_79181186</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
I have made the below changes to the function file which worked for me.
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Net;
namespace _79181186
{
public class TestFunction
{
private readonly ILogger<TestFunction> _logger;
public TestFunction(ILogger<TestFunction> logger)
{
_logger = logger;
}
[Function("test-function")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
try
{
var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteStringAsync("Request processed successfully.");
return response;
}
catch (Exception ex)
{
var errorResponse = req.CreateResponse(HttpStatusCode.BadRequest);
await errorResponse.WriteStringAsync($"An error occurred: {ex.Message}");
return errorResponse;
}
}
}
}
The request body, I am sending is of size 30MB.
Azure Functions Core Tools
Core Tools Version: 4.0.6610 Commit hash: N/A +0d55b5d7efe83d85d2b5c6e0b0a9c1b213e96256 (64-bit)
Function Runtime Version: 4.1036.1.23224
[2024-11-14T08:37:36.560Z] Found C:\Users\*****\79181186\79181186.csproj. Using for user secrets file configuration.
[2024-11-14T08:37:40.597Z] Azure Functions .NET Worker (PID: 6272) initialized in debug mode. Waiting for debugger to attach...
[2024-11-14T08:37:40.664Z] Worker process started and initialized.
Functions:
test-function: [POST] http://localhost:7256/api/test-function
For detailed output, run func with --verbose flag.
[2024-11-14T08:37:50.923Z] Executing 'Functions.test-function' (Reason='This function was programmatically called via the host APIs.', Id=72b320ab-75fd-44a6-a513-be5742ae2c08)
[2024-11-14T08:37:51.486Z] C# HTTP trigger function processed a request.
[2024-11-14T08:37:51.548Z] Executed 'Functions.test-function' (Succeeded, Id=72b320ab-75fd-44a6-a513-be5742ae2c08, Duration=1229ms)
The same has worked in portal as well.
Upvotes: 0