Skip to content

Commit

Permalink
[wasm] WebSocket is already disposed by after abort. (#55075)
Browse files Browse the repository at this point in the history
_innerWebSocket is already disposed by after abort.
  • Loading branch information
pavelsavara authored Jul 12, 2021
1 parent 102fc35 commit f28318b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,15 @@ private Task CloseAsyncCore(WebSocketCloseStatus closeStatus, string? statusDesc
_innerWebSocketCloseStatus = closeStatus;
_innerWebSocketCloseStatusDescription = statusDescription;
_innerWebSocket!.Invoke("close", (int)closeStatus, statusDescription);
_closeStatus = (int)_innerWebSocket.GetObjectProperty("readyState");
if (_innerWebSocket != null && !_innerWebSocket.IsDisposed && _state != (int)InternalState.Aborted)
{
_closeStatus = (int)_innerWebSocket.GetObjectProperty("readyState");
}
else
{
_closeStatus = 3; // (CLOSED)
}

return _tcsClose.Task;
}
catch (Exception exc)
Expand Down Expand Up @@ -612,7 +620,14 @@ private Task CloseOutputAsyncCore(WebSocketCloseStatus closeStatus, string? stat
_innerWebSocketCloseStatus = closeStatus;
_innerWebSocketCloseStatusDescription = statusDescription;
_innerWebSocket!.Invoke("close", (int)closeStatus, statusDescription);
_closeStatus = (int)_innerWebSocket.GetObjectProperty("readyState");
if (_innerWebSocket != null && !_innerWebSocket.IsDisposed && _state != (int)InternalState.Aborted)
{
_closeStatus = (int)_innerWebSocket.GetObjectProperty("readyState");
}
else
{
_closeStatus = 3; // (CLOSED)
}
OnCloseCallback(null, cancellationToken);
return Task.CompletedTask;
}
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/System.Net.WebSockets.Client/tests/AbortTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AbortTest : ClientWebSocketTestBase
{
public AbortTest(ITestOutputHelper output) : base(output) { }

[OuterLoop]
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task Abort_ConnectAndAbort_ThrowsWebSocketExceptionWithmessage(Uri server)
{
Expand All @@ -40,7 +40,7 @@ public async Task Abort_ConnectAndAbort_ThrowsWebSocketExceptionWithmessage(Uri
}
}

[OuterLoop]
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task Abort_SendAndAbort_Success(Uri server)
{
Expand All @@ -60,7 +60,7 @@ await TestCancellation(async (cws) =>
}, server);
}

[OuterLoop]
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task Abort_ReceiveAndAbort_Success(Uri server)
{
Expand All @@ -84,7 +84,7 @@ await cws.SendAsync(
}, server);
}

[OuterLoop]
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task Abort_CloseAndAbort_Success(Uri server)
{
Expand All @@ -108,7 +108,7 @@ await cws.SendAsync(
}, server);
}

[OuterLoop]
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task ClientWebSocket_Abort_CloseOutputAsync(Uri server)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ public async Task ConnectAsync_CancellationRequestedInflightConnect_ThrowsOperat

[ConditionalFact(nameof(WebSocketsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54152", TestPlatforms.Browser)]
public async Task ConnectAsync_CancellationRequestedAfterConnect_ThrowsOperationCanceledException()
{
var releaseServer = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
Expand Down

0 comments on commit f28318b

Please sign in to comment.