Skip to content

Client app crashing with "Cannot access a disposed object." exception #326

@Liviu-Ionel-Anton

Description

@Liviu-Ionel-Anton

Hi,

I am using the GraphQl.Client 3.2.1 on a project and I get an exception crashing the application after a while.
I have a client that it connects to a graphQl server from multiple threads and it is creating a subscription stream to receive notifications. The client has to do a reconnection to the server periodically. By reconnection I mean:

  • disposing the subscription created by CreateSubscriptionStream()
  • disposing error subscription from GraphqlClient.WebSocketReceiveErrors.Subscribe
  • disposing the GraphQLHttpClient instance
  • recreate GraphQLHttpClient instance
  • get error subscription from GraphqlClient.WebSocketReceiveErrors.Subscribe
  • create the subscription by CreateSubscriptionStream()
    After several reconnections I get this:

System.ObjectDisposedException
HResult=0x80131622
Message=Cannot access a disposed object.
Object name: 'System.Net.WebSockets.InternalClientWebSocket'.
Source=System
StackTrace:
at System.Net.WebSockets.WebSocketBase.ThrowIfDisposed()
at System.Net.WebSockets.WebSocketBase.WebSocketOperation.d__19.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.WebSockets.WebSocketBase.d__47.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at GraphQL.Client.Http.Websocket.GraphQLHttpWebSocket.d__32.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at GraphQL.Client.Http.Websocket.GraphQLHttpWebSocket.d__31.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at GraphQL.Client.Http.Websocket.GraphQLHttpWebSocket.<>c__DisplayClass28_1`1.<b__7>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

This exception was originally thrown at this call stack:
[External Code]

Can anyone help me understand what is the cause of this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions