aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

ResponseCompression dies and website is offline #367

Closed romanWienicke closed 5 years ago

romanWienicke commented 5 years ago

Hi,

we just had an issue with the ResponseCompression module.

Our website was running and suddenly the website was offline. We didn't get any exceptions or warnings about any exception. On the server the process "website.exe" worked (process % in the process explorer was changing).

After quite a time of try and error with our code we found out that ResponseCompression died and the whole process chain was stalled.

This was triggerd when a pdf file on the server was not found and our module returned { response.Clear(); response.StatusCode = StatusCodes.Status404NotFound; return; }

Debugging and stepping through all code we found out that the Compression module died and then also the Visual Studio stopped working for some time.

When we removed the app.UseResponseCompression(); line form our code and now everything is working.

Best regards, Roman

Tratcher commented 5 years ago

Died? What were the symptoms? Do you mean you app stopped processing any requests?

Is the issue consistent? Can you share a minimal project that reproduces the problem?

romanWienicke commented 5 years ago

I try to reproduce it without the overhead of the whole project. The app stopped to send responses, but the process seemd to be running (the process on the server had changing % in the process explorer).

romanWienicke commented 5 years ago

Hi, I think i managed to reproduce the issue sometimes :-/ https://github.com/romanWienicke/CompressionTest/tree/master/CompressionTest

the interesting part is the startup.cs file. See the comments inside the code.

It seems as the ResponseCompression was our Problem, we didn't have any Server failures after removing the line app.AddResponseComression(). We moved the compression to IIS 10.

Tratcher commented 5 years ago

Do not set a response and then call next, you get to do one or the other.

            app.Use(async (context, next) =>
            {
                var fileName = Path.GetFileName(context.Request.Path);
                var filePath = Path.Combine(env.WebRootPath, "data", fileName);
                var response = context.Response;

                // check for a missing file
                if (File.Exists(filePath))
                {
                    // pdf response
                    response.ContentType = "application/pdf";
                    await response.SendFileAsync(filePath);
                    return;
                }

                await next(); // There's an implicit 404 at the end of the pipeline if nothing else matches.
            });
romanWienicke commented 5 years ago

Ok, thank you...