Skip to content

Commit

Permalink
[wasm] Process WebSocket connection errors on NodeJS (#69858)
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf authored May 30, 2022
1 parent 486b4d1 commit 9380113
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ public async Task ConnectAsync_CookieHeaders_Success(Uri server)

[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63681", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task ConnectAsync_PassNoSubProtocol_ServerRequires_ThrowsWebSocketException(Uri server)
{
const string AcceptedProtocol = "CustomProtocol";
Expand Down Expand Up @@ -257,7 +256,6 @@ public async Task ConnectAndCloseAsync_UseProxyServer_ExpectedClosedState(Uri se
}

[ConditionalFact(nameof(WebSocketsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63672", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task ConnectAsync_CancellationRequestedBeforeConnect_ThrowsOperationCanceledException()
{
using (var clientSocket = new ClientWebSocket())
Expand All @@ -270,7 +268,6 @@ public async Task ConnectAsync_CancellationRequestedBeforeConnect_ThrowsOperatio
}

[ConditionalFact(nameof(WebSocketsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63672", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task ConnectAsync_CancellationRequestedInflightConnect_ThrowsOperationCanceledException()
{
using (var clientSocket = new ClientWebSocket())
Expand All @@ -284,7 +281,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/63671", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task ConnectAsync_CancellationRequestedAfterConnect_ThrowsOperationCanceledException()
{
var releaseServer = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
Expand Down
5 changes: 4 additions & 1 deletion src/mono/wasm/runtime/web-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ export function mono_wasm_web_socket_open_ref(uri_address: MonoObjectRef, subPro
receive_promise_control.resolve(null);
});
};
const local_on_error = (ev: any) => {
open_promise_control.reject(ev.message);
};
ws.addEventListener("message", local_on_message);
ws.addEventListener("open", local_on_open, { once: true });
ws.addEventListener("close", local_on_close, { once: true });

ws.addEventListener("error", local_on_error, { once: true });
const ws_js_handle = mono_wasm_get_js_handle(ws);
Module.setValue(web_socket_js_handle, <any>ws_js_handle, "i32");

Expand Down

0 comments on commit 9380113

Please sign in to comment.