aspnet / SignalR

[Archived] Incredibly simple real-time web for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
2.38k stars 447 forks source link

OnDisconnectedAsync(Exception exception) not fired (LongPooling) #3334

Closed NightAngell closed 5 years ago

NightAngell commented 5 years ago

Server NuGets: Microsoft.AspNetCore.App (2.1.1) include Microsoft.AspNetCore.SignalR (1.0.1) Client NPM Packages: "@aspnet/signalr": "^1.0.4" Client: TypeScript (Angular7) Server: IIS Express Operating System (Client and Server): Windows 7 Browser: Chrome

Problem: Hub method OnDisconnectedAsync(Exception exception) not fired when:

  1. User close Browser (or Tab)
  2. User lost connection with internet (Chrome: F12->Network->Offline)
  3. User refresh page

Expected behaviour: OnDisconnectedAsync(Exception exception) fired Actual behaviour: OnDisconnectedAsync(Exception exception) not fired

Code to reproduct error (Front Agnular7) https://github.com/NightAngell/SignalRErrorReproductionFront

Code to reproduct error (Backend Asp.NET Core 2.1): https://github.com/NightAngell/SignalRErrorReporductionBackend

Steps to reproduction: Backend

  1. Create new Asp.Net core 2.1 project
  2. In Startup.cs add services.AddSignalR(); and
    app.UseSignalR(options =>
            {
                options.MapHub<YourHub>("/yourHub");
            });
  3. Create YourHub : Hub
  4. In YourHub override Task OnDisconnectedAsync(Exception exception)
  5. Make breakpoint in OnDisconnectedAsync (For Debugging purpose)

Frontend

  1. Connect to server (transport: LongPolling)
  2. .then(()=>{ console.log("Connected!") });
  3. Close browser or close tab or or refresh page or (Chrome) F12->Network->Offline

*Resolve CORS problem if required

Logs: Chrome.log ChromeNetwork.har.log ASPNETCOREBUG.log

All logs from "Code to reproduct error"

BrennanConroy commented 5 years ago

We changed how some of this worked in 2.2 which will most likely resolve the issues you're seeing. Can you try out the nightly bits on the client and server?

NightAngell commented 5 years ago

I use WebSockets instead of LongPooling (on Windows 10 instead of 7 [WebSockets transport not available on win7 IIS Express]) and it work (Chrome: F12->Network->Offline dont work, but this is probably bug related to chrome tools and localhost (client and server are on localhost)*, I test it better when I deploy project to external hosting in the future [For now i write project for studies and I dont plan deploy]). I just want notify about problem, but I see this problem is known and probably resolved, then I think this issue can be closed.

*Because when is set Client as offline using chrome tools, client still can send and receive messages from server