Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.94k stars 442 forks source link

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

Open aarondandy opened 5 years ago

aarondandy commented 5 years ago

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.

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<HttpResponseMessage> 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

aarondandy commented 5 years ago

Now I seem to get 502 responses or blank 200 responses in Azure depending on planetary alignment 🤷‍♂️