Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Connection is not closed gracefully if client disconnected just before Dispose #1648

Closed
pakrym opened this issue Apr 10, 2017 · 4 comments
Closed
Assignees

Comments

@pakrym
Copy link
Contributor

pakrym commented Apr 10, 2017

Repro:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;

namespace WebApplication2
{
    public class Program : IObserver<DiagnosticListener>, IObserver<KeyValuePair<string, object>>
    {
        public static void Main(string[] args)
        {
            new Program().MainImpl(args);
        }

        public void MainImpl(string[] args)
        {

            DiagnosticListener.AllListeners.Subscribe(this);

            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseApplicationInsights()
                .ConfigureLogging(f=>f.AddConsole(LogLevel.Debug))
                .Build();

            host.Start();

            Task t;
            using (var httpClient = new HttpClient())
            {
                t = httpClient.GetAsync("http://localhost:5000//")
                    .ContinueWith(task => { Console.WriteLine("Request done"); });
                t.Wait();
            }
            Console.WriteLine("Before Dispose");
            host.Dispose();

            Console.WriteLine("After Dispose");
            Console.ReadLine();
        }

        public void OnCompleted()
        {
        }

        public void OnError(Exception error)
        {
        }

        public void OnNext(KeyValuePair<string, object> value)
        {
            if (value.Key == "Microsoft.AspNetCore.Hosting.EndRequest")
            {
                Console.WriteLine(value.Key);
                Thread.Sleep(3000);
                Console.WriteLine("After Microsoft.AspNetCore.Hosting.EndRequest");
            }
        }

        public void OnNext(DiagnosticListener value)
        {
            value.Subscribe(this);
        }
    }
}

After Microsoft.AspNetCore.Hosting.EndRequest is printed after After Dispose

@pakrym
Copy link
Contributor Author

pakrym commented Apr 10, 2017

This should be fixed as part of @halter73 connection tracking change.

@davidfowl
Copy link
Member

@muratg I assigned this one to @halter73 since he's already working on it.

@davidfowl
Copy link
Member

davidfowl commented Apr 11, 2017

This is the same issue causing #1616 to fail.

@halter73
Copy link
Member

Fixed by #1707

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants