denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.97k stars 5.23k forks source link

Playwright test runner hangs when using the `webServer` option #25193

Closed nathanwhit closed 1 day ago

nathanwhit commented 2 weeks ago

When using the webServer option in a playwright config, the playwright test runner hangs and won't exit without CTRL-C.

// playwright.config.js
import { defineConfig } from "@playwright/test";
export default defineConfig({
  webServer: { // without this option, it exits cleanly
    command: `deno run -A server.ts`,
  },
});

Repro: https://github.com/nathanwhit/deno-playwright-hang-repro. Run deno task test

lucacasonato commented 2 weeks ago

Processing the strace-ops log shows that these are the pending async ops. I presume one of them ref'd when it's meant to be unref'd?

Map(3) { "op_signal_poll" => 1, "op_spawn_wait" => 1, "op_read" => 2 }

It is not op_signal_poll, so it must either be op_spawn_wait or one of the two op_read ops.

nathanwhit commented 2 weeks ago

The root cause turned out to be us not implementing the detached option in child_process.spawn.

Creating a detached process makes a new process group, which then you can kill with process.kill(-child.pid) to kill the whole group. Since we hadn't actually detached the process, the kill call was throwing (because the negative pid signifies the process group, which didn't exist) and playwright was catching the error and didn't have a fallback. So the subprocess was never actually killed.