fix(cli): exit when a timer or socket keeps the process alive after the command
Merged
TH
18d ago+193+193+012345678901234567890123456789-6-6-0123456789
Fixes ENG-958.
What and why
- The CLI process imports
e2e.config.tsand, to collect tests, every test file (packages/e2e/src/collect/collect.ts,importModule). A timer or socket either one opens at import, such as a database pool, a keep-alive agent, or asetInterval, keepse2e runande2e listalive after the report is written and the exit code is set.e2e mcpstays alive the same way after its client disconnects. bin.tscallsexitIfStopped()(packages/e2e/src/cli/run-output.ts, added in #1206), which exits only after Ctrl-C or when the run stopped waiting for a test filter or a reporter. Any other run ends only once nothing is left open. This change builds on it and ondrainRunnerOutput()from the same file.- New
exitAfterGrace()inrun-output.ts, called frombin.tsafterexitIfStopped(), starts an unref'd 2 s timer:- A process with nothing left open ends on its own first, as today.
beforeExithooks and short timers left by user code still print (tests/integration/run-user-output.test.ts). - A process still alive when the timer fires waits for app stops already in flight (new
stopsSettled()inpackages/e2e/src/run/managed-process.ts), so an app or service command keeps its fullshutdownTimeout. Then it kills any app process group e2e started and nothing is stopping (killManagedProcessGroups), drains its output, and exits with the exit code the command set.
- A process with nothing left open ends on its own first, as today.
exitIfStopped()and its work-left-behind flag are unchanged.
Verified
Ran it locally: yes
- Testbed, the built CLI, a scratch target whose test file or config calls
setInterval(() => {}, 60_000)at import. A command still running after 25 s was killed.
main (69e123b1) | this branch | |
|---|---|---|
No open timer, e2e run | exit 0, 0.9 s | exit 0, 0.9 s |
Timer in a test file, e2e run | still running, killed | exit 0, 2.9 s |
Timer in the config, e2e run | still running, killed | exit 0, 2.9 s |
Timer in a test file, e2e list | still running, killed | exit 0, 2.4 s |
Timer in the config, e2e mcp: open_session, then the client closes stdin | still running after 20 s | exit 0, 2.0 s after the disconnect |
# tests-eng958/page.e2e.ts calls setInterval(() => {}, 60_000) at import; this branch
$ e2e run --config e2e.eng958.config.ts
✓ target "web" command ready 89ms
✓ |web| tests-eng958/page.e2e.ts (1 test) 144ms
✓ page renders 144ms
Test Files 1 passed (1)
Tests 1 passed (1)
Duration 461ms (startup 89ms)
exit 0 after 2.8s
e2e run --watchwith the timer keeps watching after the first run and exits on Ctrl-C.- The new integration tests hang on main and pass here:
runandlistexit codes with an open timer, and a 400-test--reporter jsonreport through a pipe with an open timer (cli-run.test.ts, 60 s spawn limit);e2e mcpafter a disconnect with a timer in the config (mcp-disconnect.test.ts, 20 s). - Exit codes the command sets survive the grace exit: a passed test whose cleanup failed (#1233) with a timer in the config exits 3 (
cli-run.test.ts, hangs on main). - On
ee901b33(main before #1206), an iOS simulator run and a web plus iOS run with no open timer exited as soon as the command was done.