Azure / Azure/azure-functions-host

HttpResponseMessage resulting in OutOfMemory writes guid values to response stream with 200 OK

Open
#4,030 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

OutOfMemoryExceptions (assumed, could also be a timeout, no idea, lets just call it a failure) causes a guid to be written to the response buffer in the event of a failure along with an 200 OK response. This issue is not about an OOM error but is about the behaviors when an OOM occurs.

#### Investigative information

This seems to be related to the exception occurring _after_ my function has completed as I return an HttpResponseMessage .

#### Repro steps

I am unable to reproduce this on my local machine but I can reproduce this on an S1.

```csharp
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;

namespace Yuge
{

public static class YugeResponse
{
private static readonly HttpClient Client = new HttpClient
{
Timeout = TimeSpan.FromMinutes(10)
};

[FunctionName("Yuge")]
public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
{
const string url = "http://releases.ubuntu.com/18.04.1/ubuntu-18.04.1-desktop-amd64.iso";
var source = await Client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
var sourceContent = source.Content;
var sourceStream = await sourceContent.ReadAsStreamAsync();

var destinationContent = new StreamContent(sourceStream);
destinationContent.Headers.ContentType = sourceContent.Headers.ContentType;
destinationContent.Headers.ContentLength = sourceContent.Headers.ContentLength;

return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = destinationContent
};
}
}

}
```

#### Expected behavior

I expect a request made to this resource to fail when memory limits are exceeded *after* the HttpResponseMessage is returned.

#### Actual behavior

The function returns an HTTP 200 OK with a guid value in the response body. Note that the OOM is not occurring _within_ the function itself but after the function has returned. I have no idea what this guid is or where it comes from.

#### Known workarounds

I don't know of a workaround for this particular issue. I will open another issue related to the OOM I am experiencing.

#### Related information

Related information

* Programming language used: C#
* aspnetcore2.2

Contributor guide

Open the contributing guide

Research direction

Start with the HttpTrigger Run entry point and the HttpResponseMessage/StreamContent handling shown in the reproduction, then trace how the host writes responses after the function returns. Compare the expected failure behavior with the reported 200 OK response containing a GUID; the issue is complete when this post-return failure path is understood and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.