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][MT] silence "keeping the worker alive for asynchronous operation" #98631

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion src/mono/browser/runtime/loader/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ENVIRONMENT_IS_WORKER, loaderHelpers } from "./globals";

const methods = ["debug", "log", "trace", "warn", "info", "error"];
const prefix = "MONO_WASM: ";
const emscriptenNoise = "keeping the worker alive for asynchronous operation";
let consoleWebSocket: WebSocket;
let theConsoleApi: any;
let originalConsoleMethods: any;
Expand Down Expand Up @@ -71,7 +72,7 @@ function proxyConsoleMethod(prefix: string, func: any, asJson: boolean) {

if (typeof payload === "string") {
if (WasmEnableThreads) {
if (ENVIRONMENT_IS_WORKER && payload.indexOf("keeping the worker alive for asynchronous operation") !== -1) {
if (ENVIRONMENT_IS_WORKER && payload.indexOf(emscriptenNoise) !== -1) {
// muting emscripten noise
return;
}
Expand Down Expand Up @@ -101,6 +102,19 @@ function proxyConsoleMethod(prefix: string, func: any, asJson: boolean) {
};
}

export function mute_worker_console(): void {
originalConsoleMethods = {
...console
};
console.error = (...args: any[]) => {
const payload = args.length > 0 ? args[0] : "";
if (payload.indexOf(emscriptenNoise) !== -1) {
return;
}
originalConsoleMethods.error(...args);
};
}

export function setup_proxy_console(id: string, console: Console, origin: string): void {
theConsoleApi = console as any;
threadNamePrefix = id;
Expand Down
10 changes: 8 additions & 2 deletions src/mono/browser/runtime/loader/worker.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import WasmEnableThreads from "consts:wasmEnableThreads";

import { MonoConfigInternal, WorkerToMainMessageType, monoMessageSymbol } from "../types/internal";
import { MonoConfig } from "../types";
import { deep_merge_config, normalizeConfig } from "./config";
import { ENVIRONMENT_IS_WEB, loaderHelpers } from "./globals";
import { mono_log_debug } from "./logging";
import { mono_log_debug, mute_worker_console } from "./logging";

export function setupPreloadChannelToMainThread() {
if (!WasmEnableThreads) return;
const channel = new MessageChannel();
const workerPort = channel.port1;
const mainPort = channel.port2;
Expand All @@ -31,6 +34,7 @@ let workerMonoConfigReceived = false;

// called when the main thread sends us the mono config
function onMonoConfigReceived(config: MonoConfigInternal): void {
if (!WasmEnableThreads) return;
if (workerMonoConfigReceived) {
mono_log_debug("mono config already received");
return;
Expand All @@ -45,5 +49,7 @@ function onMonoConfigReceived(config: MonoConfigInternal): void {
if (ENVIRONMENT_IS_WEB && config.forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
loaderHelpers.setup_proxy_console("worker-idle", console, globalThis.location.origin);
}
else if (ENVIRONMENT_IS_WEB && !loaderHelpers.config.forwardConsoleLogsToWS) {
mute_worker_console();
}
}

2 changes: 0 additions & 2 deletions src/mono/browser/runtime/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export async function mono_run_main(main_assembly_name?: string, args?: string[]
}
}



export function nativeExit(code: number) {
if (WasmEnableThreads) {
cancelThreads();
Expand Down
Loading