Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Random 502 cgi gateway error when response 304 then flush response #219

Closed
303248153 opened this issue Jul 2, 2016 · 2 comments
Closed

Comments

@303248153
Copy link

303248153 commented Jul 2, 2016

First I found this problem with my project, sometime static files will return 502 with cgi gateway error.
Today I do a diggup, to reproduce this problem you needs:

  • Host asp.net core application on IIS, if you run with kestrel only, this problem won't happen.
  • Response 304, only 304 cause this problem.
  • Explict flush the response
  • Do the request parallel

I uploaded a minimal reproduce project, please check it.
It maybe a thread race condition problem because only parallel request will cause this problem.
WebApplication1.zip

I don't known if it's same with other 502.3 issues,
and I already using asp.net core 1.0.0 as you can see in the project.json.

@Tratcher
Copy link
Member

Tratcher commented Jul 5, 2016

This seems to be a Kestrel issue. Updated repro code:

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(ThreadPoolVersion);
        }

        private async Task DefaultVersion(HttpContext context)
        {
            if (context.Request.Path == "/")
            {
                context.Response.ContentType = "text/html";
                var html = string.Join("",
                    Enumerable.Range(0, 100).Select(n => $"<img src='/{n}.jpg'></img>"));
                await context.Response.WriteAsync(html);
            }
            else if (context.Request.Path.Value.EndsWith(".jpg"))
            {
                context.Response.Headers.Add("Last-Modified", "Fri, 17 Jun 2016 06:56:44 GMT");
                context.Response.ContentType = "image/jpeg";
                context.Response.StatusCode = 304;
                await context.Response.Body.FlushAsync();
                // context.Response.Body.Flush();
            }
        }

I saw the same behaviors with both the DefaultVersion and ThreadPoolVersion repro methods. If I start the site with just Kestrel then the browser will make many parallel requests but only the first 8 will complete, the remainder time out. If I launch IIS Express then most of the requests complete, but 1/10 fail with a 502.

@Tratcher
Copy link
Member

Tratcher commented Jul 5, 2016

This issue was moved to aspnet/KestrelHttpServer#952

@Tratcher Tratcher closed this as completed Jul 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants