Skip to content

playwright-cli list sometimes never exits when the server registry has stale entries #549

Open

Description

Version

@playwright/cli 0.1.25 (playwright-core 1.66.0-alpha-2026-11-18), Node 22, Linux

What happens

playwright-cli list prints its output and then never exits when at least two stale entries (daemons that are gone) sit in the server registry, ~/.cache/ms-playwright/b. A daemon stopped with detach leaves its entry there, so after a few attach/detach cycles any script that runs list can hang.

Steps to reproduce

No browser needed:

export HOME=$(mktemp -d)
mkdir -p "$HOME/.cache/ms-playwright/b"
for run in $(seq 1 10); do
  for i in 1 2; do
    g="browser@$(head -c16 /dev/urandom | od -An -tx1 | tr -d ' \n')"
    printf '{"playwrightVersion":"x","title":"t","browser":{"guid":"%s","browserName":"chromium","launchOptions":{}},"endpoint":"%s/dead-%s.sock"}' \
      "$g" "$HOME" "$g" > "$HOME/.cache/ms-playwright/b/$g"
  done
  timeout 10 playwright-cli list > /dev/null; echo "exit=$?"   # 124 = still running after 10 s
  rm -f "$HOME/.cache/ms-playwright/b/"*
done

Expected

list exits once it has printed the sessions.

Actual

It hangs in most runs: 18 of 20 on my machine. It is a race, so the rate depends on load.

Cause, as far as I can tell

  • ServerRegistry.list() (packages/playwright-core/src/serverRegistry.ts) deletes the stale entries while its chokidar watcher on the registry directory is still running, then calls void watcher.close() without waiting for it.
  • The bundled chokidar 4.0.3 receives the unlink events after close(). In _remove, if (!isDirectory && this._watched.size === 1) this.add(...) adds the directory again and sets closed back to false. Nothing closes that new watch, so the process stays alive. A Node diagnostic report of a hung list shows that directory watch as the only active handle.
  • chokidar 5 still has that code. chokidar 6 makes close() final, but it requires Node 22.22 or later.

Possible fix

Delete the stale entries only after the watcher has stopped, and await watcher.close(). With that change I saw 0 hangs in 20 runs and 0 in 10, but an unpatched run also passed 20 of 20 once, so the race needs a deterministic test rather than counts.

I'm happy to send a PR with a test if this is accepted.

Activity

  1. microsoft-playwright-automation commented on Nov 19, 2026

    @microsoft-playwright-automation
  2. microsoft-playwright-automation commented on Nov 19, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot. I reproduced this on Linux and prepared an upstream fix.

    Reproduced on current Playwright main (1.66.0-next, 1664ab289928a7ad500ea735859fc3b9d61dd5d6, Node 24.22.2). Stale-file deletion can leave chokidar callbacks that reopen the watcher after it closes. The fix waits for the temporary watcher to close before deleting stale entries, and extends the existing list test with a deterministic check of that ordering.

    Reproduction and checks

    With two registry descriptors pointing to a nonexistent Unix socket, 1 of 20 unmodified CLI processes printed (no browsers) but failed to exit within two seconds. With the fix, all 20 exited normally and removed both entries.

    The regression test records the number of open native registry watches when each stale file is deleted: the unmodified code produces [3, 3], whereas the fixed code produces [0, 0]. This check does not depend on reproducing the hang by chance.

    npm run build, npm run flint, and all 78 tests in cli-session.spec.ts and cli-endpoint.spec.ts passed across Chromium, Firefox, and WebKit.

    The change is in microsoft/playwright; the CLI package needs a subsequent Playwright dependency roll to receive it.

    Draft PR: microsoft/playwright#44241

    Triaged on Linux by the Playwright bot - agent run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions