Skip to content

[Bug]: Leaky Electron IPC handlers cause tests to hang on Linux/Windows #39248

@RyanGroch

Description

@RyanGroch

Version

1.58.2

Steps to reproduce

I've created a repro here. To use it, clone the repo and run:

npm install
npm run pre:e2e
npm run e2e

Or, you can fork the repo and run the Playwright CI workflow in GitHub Actions.

A more general way to reproduce the issue is as follows:

  1. Initialize an Electron app, maybe using create-electron-app. Add Playwright to the project.
  2. Write an IPC handler in the Electron app which spawns a long-running shell that will not finish executing before Playwright's timeout for each test.
  3. Write and run a Playwright test which causes the IPC handler created in step 2 to execute (maybe by clicking a button that triggers it).
  4. Observe that on Linux (and Windows, if you don't force-kill the Electron app), tests which should otherwise pass end up hanging until the timeout and thus fail. It seems that Playwright cannot fully clean up the Electron app if there's a leaky IPC handler. This issue does not seem to exist on macOS.

One example of an IPC handler for step 2 might be as follows, as long as Playwright's timeout is less than the sleep count (75 seconds in this case):

// main.ts of the Electron app

import { ipcMain } from "electron";
import os from "node:os";
import { promisify } from "node:util";
import { exec } from "node:child_process";

// other code here

ipcMain.on("create-leak", async () => {
  // This doesn't have to be sleep; any long-running shell command can cause a leak
  const cmd =
    os.platform() === "win32"
      ? 'powershell.exe -Command "Start-Sleep -Seconds 75"'
      : "sleep 75";

  await promisify(exec)(cmd);
});

Expected behavior

Tests that execute a leaky IPC handler should pass on Linux and Windows the way that they currently do on macOS. I don't think it makes sense for tests to hang and fail just because an IPC handler spawned a long-running subprocess that didn't finish before the end of the test.

In the case of the repro I linked to above, I would like tests/broken.spec.ts to pass on Linux. This can be done either with a patch to Playwright, or by showing me a workaround to add to the setup/teardown of my tests.

Actual behavior

Tests that execute a leaky IPC handler will hang on Windows and Linux, causing tests to fail when they should otherwise pass.

In my repro, tests/broken.spec.ts currently fails on Linux but passes on macOS and Windows. It passes on Windows only because I taskkill the Electron app during Playwright's cleanup, which is a Windows-only workaround.

There aren't really any relevant error messages, except for Playwright's report at the end of the tests:

Running 2 tests using 2 workers
  1) tests/broken.spec.ts:4:5 › text is visible after clicking the button ──────────────────────────

    Tearing down "electronApp" exceeded the test timeout of 60000ms.

  1 failed
    tests/broken.spec.ts:4:5 › text is visible after clicking the button ───────────────────────────
  1 passed (2.0m)

Additional context

If there's no official fix for this, I'd also be interested in any other workaround for Linux if one exists.

Things I've tried:

  • Using kill and pkill on Linux to terminate the electron app during cleanup, but this doesn't seem to prevent the tests from hanging and failing.
  • Calling electronApp.process().kill() during cleanup, which also doesn't seem to help.

Also, if you want to reproduce the bug on Windows, then you can still use the repro I linked to above. However, you'll need to change this code in tests/helpers.ts:

if (os.platform() === "win32") {
  try {
    execSync("taskkill /f /t /im playwrightbug.exe");
  } catch (error) {
    console.warn(error);
  }
} else {
  await electronApp.close();
}

And replace it with just:

await electronApp.close();

Environment

System:
    OS: Linux 5.15 Linux Mint 21.2 (Victoria)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 10.49 GB / 15.49 GB
    Container: Yes
  Binaries:
    Node: 22.12.0 - /home/me/.nvm/versions/node/v22.12.0/bin/node
    Yarn: 1.22.22 - /home/me/.nvm/versions/node/v22.12.0/bin/yarn
    npm: 10.9.0 - /home/me/.nvm/versions/node/v22.12.0/bin/npm
    pnpm: 10.12.1 - /home/me/.nvm/versions/node/v22.12.0/bin/pnpm
  IDEs:
    VSCode: 1.109.0 - /usr/bin/code
  Languages:
    Bash: 5.1.16 - /usr/bin/bash
  npmPackages:
    @playwright/test: ^1.58.2 => 1.58.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions