Skip to content

LongPollingTransport threw ObjectDisposedException in AbortResetEvent.Set() #1691

Closed
jcondex opened this Issue Mar 13, 2013 · 1 comment

3 participants

@jcondex
jcondex commented Mar 13, 2013

LongPollingTransport threw an ODE complaining that AbortResetEvent had already been disposed.

This happened because HttpBasedTransport was disposed and then the finally block of PollingLoop occurred.

Here is the exception:

System.ObjectDisposedException was unhandled by user code
  HResult=-2146232798
  Message=Safe handle has been closed
  Source=mscorlib
  ObjectName=""
  StackTrace:
       at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
       at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
       at System.Threading.EventWaitHandle.Set()
       at Microsoft.AspNet.SignalR.Client.Transports.LongPollingTransport.<>c__DisplayClassc.<PollingLoop>b__0(Task`1 task) in c:\Users\jconde\Documents\GitHub\SignalR\src\Microsoft.AspNet.SignalR.Client\Transports\LongPollingTransport.cs:line 144
       at System.Threading.Tasks.Task.Execute()
  InnerException: 

A simple fix for this is to do the following in the finally block:

                    if (AbortResetEvent != null && !AbortResetEvent.SafeWaitHandle.IsClosed)
                    {
                        AbortResetEvent.Set();
                    }

ServerSentEvents seems immune to this because AbortResetEvent.Set() is not called within a finally block.

@davidfowl davidfowl was assigned Mar 18, 2013
@davidfowl
SignalR member

Seens the same error on our CI.

MSBuild.exe Error: 0 : Unobserved task exception: System.ObjectDisposedException: Safe handle has been closed
   at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
   at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
   at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
   at System.Threading.EventWaitHandle.Set()
   at Microsoft.AspNet.SignalR.Client.Transports.LongPollingTransport.<>c__DisplayClassc.<PollingLoop>b__0(Task`1 task) in d:\BuildAgent\work\2ebbeab341bc5e27\src\Microsoft.AspNet.SignalR.Client\Transports\LongPollingTransport.cs:line 144
   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
@halter73 halter73 was assigned Apr 9, 2013
@jcondex jcondex was assigned Apr 16, 2013
@davidfowl davidfowl closed this Apr 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.