Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(engine): cover the shared puppeteer args mutation

Yudhi Armyndharise66f6a27d3b0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d208bb800..49f782ce5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- Running more than one session no longer corrupts the Chromium launch flags of every
+ session started after the first. The whatsapp-web.js adapter appended its per-session
+ arguments (`--proxy-server`, and the `--openwa-session=<id>` process marker) directly
+ to the array returned by `engine.puppeteer.args` — but `ConfigService` hands back a
+ live reference into the cached configuration tree, so every session shared one array
+ and each start mutated it permanently. Three symptoms followed: the argument list grew
+ without bound across starts and reconnects until Chromium refused to launch; a session
+ configured without a proxy inherited the previous session's `--proxy-server` and routed
+ its traffic through it; and because the orphaned-Chromium sweep identifies processes by
+ substring-matching the session marker, a restart of one session could `SIGKILL` another
+ session's healthy browser. The adapter now copies the array before appending, so the
+ shared configuration is never mutated. Fixed in #840 — thanks @szmazhr.
+
- Typing a session name in the dashboard's **Create New Session** dialog no longer
stalls after the first character. The shared `Modal` component ran its initial-focus
step inside a `useEffect` whose dependency array included `onClose`, and callers pass
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
index 7e6276530..0ecb769fb 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
@@ -2657,6 +2657,34 @@ describe('WhatsAppWebJsAdapter orphaned Chromium sweep (pre-launch)', () => {
expect(client.options.puppeteer?.args).toContain(`--openwa-session=${SESSION_ID}`);
});
+ it('does not mutate the caller-owned puppeteer args array shared across sessions', async () => {
+ // Every adapter receives the SAME array instance — ConfigService.get() returns a live reference
+ // into the cached config tree, via the plugin path (plugins/engines/whatsapp-web-js) and the
+ // factory fallback alike. Appending in place therefore rewrites global config for the rest of
+ // the process lifetime, leaking one session's flags (proxy, session marker) into every later
+ // launch. Without the defensive copy this assertion sees both session markers accumulate.
+ const sharedArgs = ['--no-sandbox'];
+ const argsFor = async (sessionId: string): Promise<string[] | undefined> => {
+ const adapter = new WhatsAppWebJsAdapter({
+ sessionId,
+ sessionDataPath: './data/sessions',
+ puppeteer: { args: sharedArgs },
+ });
+ await adapter.initialize({});
+ return (adapter as unknown as { client: { options: { puppeteer?: { args?: string[] } } } }).client.options
+ .puppeteer?.args;
+ };
+
+ await argsFor('sess-a');
+ const argsB = await argsFor('sess-b');
+
+ expect(sharedArgs).toEqual(['--no-sandbox']);
+ expect(argsB).toContain('--openwa-session=sess-b');
+ // The cross-session leak that let a restart of sess-a SIGKILL sess-b's live browser: the sweep
+ // substring-matches this marker against the full `ps` command line.
+ expect(argsB).not.toContain('--openwa-session=sess-a');
+ });
+
it('SIGKILLs a Chromium process carrying this session marker and logs the sweep', async () => {
mockPsResult({
stdout: psTable([