Azure / azure-relay-dotnet

☁️ .NET Standard client library for Azure Relay Hybrid Connections

Home Page:https://docs.microsoft.com/en-us/azure/service-bus-relay/relay-what-is-it

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C# Client may try to close a disposed WebSocket

masters3d opened this issue · 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 aspnet/SignalR#1004

await this.webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "CloseAsync", linkedCancelSource.Token).ConfigureAwait(false);

await this.webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Shutdown", linkedCancelSource.Token).ConfigureAwait(false);

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: