fix(core): cancel running calls by name when a session closes
Merged
OK
8d ago+181+181+012345678901234567890123456789-18-18-01234567890123456789
- Closing an
@e2e-dev/coresession or host while calls still run on it is how a program cancels. Core treated it as a missingawait, becauselaunchAttemptran the runner'sabandonRunning()for core sessions too. - Each running step now fails with
CANCELLEDand a message that names it, with the stack of the call.close()does not fail for them. - Only a session opened with
cancelsOnClosetakes the new path, which is core'slaunch(packages/core/src/run/standalone-attempt.ts). Runner attempts and MCP sessions keepSTEP_NOT_AWAITED. StepRecorder.nameRunning(reason, error)registers each running step's error right before the abort. A step that failed on its own, or that another abort reached first, keeps that failure.
const open = session.app.open('/slow');
await session.close(); // resolves
await open; // CANCELLED: the session closed while app.open "/slow" was running
Why
A nightly report showed a program dying with a bare E2EError: the session is closed and blamed a concurrent launch() of two engines. Hosts turned out to be independent: the report's script passed 8 of 8 runs here, and a failing mobile launch left a concurrent web session untouched. The trace is what a call left running at session disposal produces, and it named neither the call nor its line.
For the reviewer to decide
A call that nothing awaits rejects unhandled when its session closes, so Node.js ends the program during the close and the host is never disposed.
- On main that already happened for calls an
asyncmethod wraps (waitFor,scrollUntilVisible). - For calls that return the step's own promise (
tap,app.open), main observed the rejection, finished the close, and threwthe test body returned before ... finishedfromclose(). This PR makes them end the program too, with the named error. - Keeping the old behavior for those calls means
close()fails on every deliberate cancel, Ctrl-C included. - The alternative that keeps teardown is what the runner does: an
unhandledRejectionlistener while a host is open. It is a process-wide hook in a library, so it is not in this PR.
Not in this PR
- Reads (
textContent(),count()) andsaveState()are not steps. One cut mid-flight still fails withoperation cancelled. - A program with no
finallyand noawait usingaround a running call still exits 1 on Ctrl-C without disposing its host, as on main.
Verified
Ran it locally: yes
- Scratch programs on the built packages,
@e2e-dev/webon Chromium againsthttps://books.toscrape.com, each run on main and on this branch. - The new tests in
core.test.ts,core-signals.test.ts, andstep-name-running.test.tsfail on main and pass here.
| Program | main | this branch |
|---|---|---|
await using session, locator.waitFor() not awaited | E2EError: the session is closed at Object.closed (launch.js:141), exit 1 | E2EError: the session closed while locator.waitFor "getByText("this text is not on the page") → visible" was running at runWeb (signature3.ts:20), exit 1 |
app.open("/") awaited, session.close() called 300 ms in | open: CANCELLED the session is closed; close throws the test body returned before app.open "/" finished; put await in front of every step call | open: CANCELLED the session closed while app.open "/" was running; close resolves |
SIGINT during an awaited app.open("/") | stderr @e2e-dev/core: closing a host on SIGINT failed: closing the host failed: the test body returned before app.open "/" finished; ..., exit 130 | empty stderr, exit 130 |