Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser] mono runtime already exited with 0 - silence WS #92479

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/mono/wasm/runtime/web-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import MonoWasmThreads from "consts:monoWasmThreads";

import { prevent_timer_throttling } from "./scheduling";
import { Queue } from "./queue";
import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, createPromiseController, mono_assert } from "./globals";
import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, createPromiseController, loaderHelpers, mono_assert } from "./globals";
import { setI32, localHeapViewU8 } from "./memory";
import { VoidPtr } from "./types/emscripten";
import { PromiseController } from "./types/internal";
Expand Down Expand Up @@ -58,17 +58,20 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
ws.binaryType = "arraybuffer";
const local_on_open = () => {
if (ws[wasm_ws_is_aborted]) return;
if (loaderHelpers.is_exited()) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be before if (ws[wasm_ws_is_aborted]) return too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't really matter.

open_promise_control.resolve(ws);
prevent_timer_throttling();
};
const local_on_message = (ev: MessageEvent) => {
if (ws[wasm_ws_is_aborted]) return;
if (loaderHelpers.is_exited()) return;
_mono_wasm_web_socket_on_message(ws, ev);
prevent_timer_throttling();
};
const local_on_close = (ev: CloseEvent) => {
ws.removeEventListener("message", local_on_message);
if (ws[wasm_ws_is_aborted]) return;
if (loaderHelpers.is_exited()) return;

onClosed(ev.code, ev.reason);

Expand All @@ -93,6 +96,7 @@ export function ws_wasm_create(uri: string, sub_protocols: string[] | null, rece
};
const local_on_error = (ev: any) => {
if (ws[wasm_ws_is_aborted]) return;
if (loaderHelpers.is_exited()) return;
ws.removeEventListener("message", local_on_message);
const error = new Error(ev.message || "WebSocket error");
mono_log_warn("WebSocket error", error);
Expand Down