From 525aa4d10f6e72ef2996fe2cd728c62d29c1ca7c Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Tue, 25 Jul 2023 07:10:08 +0000 Subject: [PATCH] Bug 1844133 - [remote] WebSocketConnection logs should be truncated for huge objects r=webdriver-reviewers,Sasha Puppeteer happens to send huge payloads as part of their test suite when using their $$eval API. This is because they pass back and forth nodeLists for which all children are serialized by default. This could be avoided by changing the serialization options (see https://github.com/puppeteer/puppeteer/issues/10582) But without such a fix, we need to cap the size of the websocket logs, otherwise the logparser is unable to handle the logs from the bidi puppeteer job. Differential Revision: https://phabricator.services.mozilla.com/D184108 --- remote/shared/WebSocketConnection.sys.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/remote/shared/WebSocketConnection.sys.mjs b/remote/shared/WebSocketConnection.sys.mjs index 60e03bbfcfe7..d2ceb6ee1423 100644 --- a/remote/shared/WebSocketConnection.sys.mjs +++ b/remote/shared/WebSocketConnection.sys.mjs @@ -17,6 +17,8 @@ ChromeUtils.defineESModuleGetters(lazy, { XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get()); +const MAX_LOG_LENGTH = 2500; + export class WebSocketConnection { /** * @param {WebSocket} webSocket @@ -45,12 +47,20 @@ export class WebSocketConnection { return value; } - const payload = JSON.stringify( + let payload = JSON.stringify( data, replacer, lazy.Log.verbose ? "\t" : null ); + if (payload.length > MAX_LOG_LENGTH) { + // Even if we truncate individual values, the resulting message might be + // huge if we are serializing big objects with many properties or items. + // Truncate the overall message to avoid issues in logs. + const truncated = payload.substring(0, MAX_LOG_LENGTH); + payload = `${truncated} [... truncated after ${MAX_LOG_LENGTH} characters]`; + } + lazy.logger.debug( `${this.constructor.name} ${this.id} ${direction} ${payload}` );