azure-relay-dotnet icon indicating copy to clipboard operation
azure-relay-dotnet copied to clipboard

C# Client may try to close a disposed WebSocket

Open masters3d opened this issue 4 years ago • 0 comments

Actual Behavior

  1. Lets me close a disposed socked which causes an exception
The service threw an unhandled exception, System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.WebSockets.ClientWebSocket'.
   at System.Net.WebSockets.ClientWebSocket.ThrowIfNotConnected()
   at System.Net.WebSockets.ClientWebSocket.CloseOutputAsync(WebSocketCloseStatus closeStatus, String statusDescription, CancellationToken cancellationToken)
   at Microsoft.Azure.Relay.WebSocketStream.<OnShutdownAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Relay.HybridConnectionStream.<ShutdownAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
  1. The problem is very similar to a singalIR issues https://github.com/aspnet/SignalR/issues/1004

https://github.com/Azure/azure-relay-dotnet/blob/5e41166816ac7602a6574d49fb0e010e5d4e2295/src/Microsoft.Azure.Relay/WebSocketStream.cs#L80 https://github.com/Azure/azure-relay-dotnet/blob/5e41166816ac7602a6574d49fb0e010e5d4e2295/src/Microsoft.Azure.Relay/WebSocketStream.cs#L153

The real issue is that the websockets client throws :( https://github.com/dotnet/runtime/blob/d6bf13a39c8ccb8fa7815a2f7e4387120a837138/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocket.cs#L226

Expected Behavior

  1. Do not throw on closing a disposed socket
  2. or throw? Doesn't seem correct since even singalIR addressed the issue.

Versions

  • OS platform and version:
  • .NET Version:
  • NuGet package version or commit ID:

masters3d avatar May 29 '20 04:05 masters3d