question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignalR: `Error when dispatching '"OnDisconnectedAsync"' on hub` and `Failed disposing connection`

See original GitHub issue

Describe the bug

After migrating my application from ASP.NET Core 2.1 (net471) to ASP.NET Core 2.2 (netcoreapp2.2 and InProcess hosting model) I found some exceptions in our log system related to SignalR.

These exceptions are always happening after IIS shutting down the application.

And I have some errors logged in the Event Viewer at the same time.

Additional context

09:12:07.250 ERR Error when dispatching '"OnDisconnectedAsync"' on hub.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateScope()
   at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.OnDisconnectedAsync(HubConnectionContext connection, Exception exception)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.HubOnDisconnectedAsync(HubConnectionContext connection, Exception exception)
09:12:07.939 ERR Error when dispatching '"OnDisconnectedAsync"' on hub.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateScope()
   at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.OnDisconnectedAsync(HubConnectionContext connection, Exception exception)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.HubOnDisconnectedAsync(HubConnectionContext connection, Exception exception)
09:12:08.114 ERR Failed disposing connection "hV2ao8YCcPSDKOtG6K0B4g".
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateScope()
   at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.OnDisconnectedAsync(HubConnectionContext connection, Exception exception)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.HubOnDisconnectedAsync(HubConnectionContext connection, Exception exception)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.RunHubAsync(HubConnectionContext connection)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.OnConnectedAsync(ConnectionContext connection)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.OnConnectedAsync(ConnectionContext connection)
   at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionDispatcher.ExecuteApplication(ConnectionDelegate connectionDelegate, HttpConnectionContext connection)
   at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionContext.WaitOnTasks(Task applicationTask, Task transportTask, Boolean closeGracefully)
   at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager.DisposeAndRemoveAsync(HttpConnectionContext connection, Boolean closeGracefully)
   at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionContext.DisposeAsync(Boolean closeGracefully)
   at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager.DisposeAndRemoveAsync(HttpConnectionContext connection, Boolean closeGracefully)

Event Viewer logs

Log Name:      Application
Source:        IIS AspNetCore Module V2
Date:          12/25/2018 9:12:06 AM
Event ID:      1033
Task Category: None
Level:         Information
Keywords:      Classic
User:          N/A
Computer:      THE_SERVER
Description:
Application 'MACHINE/WEBROOT/APPHOST/THE_APP' has shutdown.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="IIS AspNetCore Module V2" />
    <EventID Qualifiers="0">1033</EventID>
    <Level>4</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2018-12-25T14:12:06.000000000Z" />
    <EventRecordID>1336018</EventRecordID>
    <Channel>Application</Channel>
    <Computer>THE_SERVER</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Application 'MACHINE/WEBROOT/APPHOST/THE_APP' has shutdown.</Data>
    <Data>Process Id: 21132.</Data>
    <Data>File Version: 12.2.18316.0. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: ce8cf65589734f82b0536c543aba5bd60d0a5a98</Data>
  </EventData>
</Event>
Log Name:      Application
Source:        Application Error
Date:          12/25/2018 9:12:07 AM
Event ID:      1000
Task Category: (100)
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      THE_SERVER
Description:
Faulting application name: w3wp.exe, version: 8.5.9600.16384, time stamp: 0x5215df96
Faulting module name: KERNELBASE.dll, version: 6.3.9600.18938, time stamp: 0x5a7ddf0a
Exception code: 0xe0455858
Fault offset: 0x0000000000008eac
Faulting process id: 0x528c
Faulting application start time: 0x01d49b68baf0ffe9
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\windows\system32\KERNELBASE.dll
Report Id: 0f5a2200-084f-11e9-80d8-ac1f6b222a7d
Faulting package full name: 
Faulting package-relative application ID: 
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Application Error" />
    <EventID Qualifiers="0">1000</EventID>
    <Level>2</Level>
    <Task>100</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2018-12-25T14:12:07.000000000Z" />
    <EventRecordID>1336019</EventRecordID>
    <Channel>Application</Channel>
    <Computer>THE_SERVER</Computer>
    <Security />
  </System>
  <EventData>
    <Data>w3wp.exe</Data>
    <Data>8.5.9600.16384</Data>
    <Data>5215df96</Data>
    <Data>KERNELBASE.dll</Data>
    <Data>6.3.9600.18938</Data>
    <Data>5a7ddf0a</Data>
    <Data>e0455858</Data>
    <Data>0000000000008eac</Data>
    <Data>528c</Data>
    <Data>01d49b68baf0ffe9</Data>
    <Data>c:\windows\system32\inetsrv\w3wp.exe</Data>
    <Data>C:\windows\system32\KERNELBASE.dll</Data>
    <Data>0f5a2200-084f-11e9-80d8-ac1f6b222a7d</Data>
    <Data>
    </Data>
    <Data>
    </Data>
  </EventData>
</Event>
Log Name:      Application
Source:        Windows Error Reporting
Date:          12/25/2018 9:12:07 AM
Event ID:      1001
Task Category: None
Level:         Information
Keywords:      Classic
User:          N/A
Computer:      THE_SERVER
Description:
Fault bucket , type 0
Event Name: APPCRASH
Response: Not available
Cab Id: 0

Problem signature:
P1: w3wp.exe
P2: 8.5.9600.16384
P3: 5215df96
P4: KERNELBASE.dll
P5: 6.3.9600.18938
P6: 5a7ddf0a
P7: e0455858
P8: 0000000000008eac
P9: 
P10: 

Attached files:

These files may be available here:


Analysis symbol: 
Rechecking for solution: 0
Report Id: 0f5a2200-084f-11e9-80d8-ac1f6b222a7d
Report Status: 0
Hashed bucket: 
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Windows Error Reporting" />
    <EventID Qualifiers="0">1001</EventID>
    <Level>4</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2018-12-25T14:12:07.000000000Z" />
    <EventRecordID>1336020</EventRecordID>
    <Channel>Application</Channel>
    <Computer>THE_SERVER</Computer>
    <Security />
  </System>
  <EventData>
    <Data>
    </Data>
    <Data>0</Data>
    <Data>APPCRASH</Data>
    <Data>Not available</Data>
    <Data>0</Data>
    <Data>w3wp.exe</Data>
    <Data>8.5.9600.16384</Data>
    <Data>5215df96</Data>
    <Data>KERNELBASE.dll</Data>
    <Data>6.3.9600.18938</Data>
    <Data>5a7ddf0a</Data>
    <Data>e0455858</Data>
    <Data>0000000000008eac</Data>
    <Data>
    </Data>
    <Data>
    </Data>
    <Data>
    </Data>
    <Data>
    </Data>
    <Data>
    </Data>
    <Data>0</Data>
    <Data>0f5a2200-084f-11e9-80d8-ac1f6b222a7d</Data>
    <Data>0</Data>
    <Data>
    </Data>
  </EventData>
</Event>

dotnet --info

Host (useful for support):
  Version: 2.2.0
  Commit:  1249f08fed

.NET Core SDKs installed:
  No SDKs were found.

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
analogrelaycommented, May 30, 2019

Suggest considering this for 3.1. We don’t have the capacity to do it in 3.0 given the current list of work.

0reactions
davidfowlcommented, Apr 6, 2021

I haven’t seen reports of this recently. Is it still happening?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to resolve service for type 'Microsoft.AspNetCore. ...
fail: Microsoft.AspNetCore.SignalR.HubConnectionHandler[1] Error when dispatching 'OnConnectedAsync' on hub. System.InvalidOperationException: ...
Read more >
Log exceptions and Azure App Service 100% CPU #8972
SignalR.HubConnectionHandler - Error when dispatching 'OnDisconnectedAsync' on hub. System.ObjectDisposedException: Cannot access a disposed ...
Read more >
Understanding and Handling Connection Lifetime Events ...
This article provides an overview of the SignalR connection, reconnection, and disconnection events that you can handle, and timeout and ...
Read more >
OpenID Connect HTTP 500 Error
Hi Guys, I've noticed a problem with using OpenID Connect to use AzureAD accounts ... Error when dispatching 'OnDisconnectedAsync' on hub.
Read more >
https://raw.githubusercontent.com/dotnet/aspnetcor...
AspNetCore.Http.Connections.Features; using Microsoft.AspNetCore.SignalR. ... Equal("Failed to invoke 'OnDisconnectedAsync' due to an error on the server.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found