Skip to content

Make backend shutdown safe on Python 3.13 and report a stuck backend - #39

Merged
CSSFrancis merged 2 commits into
mainfrom
fix/backend-shutdown
Nov 8, 2026
Merged

CSSFrancis merged 2 commits into
mainfrom
fix/backend-shutdown

Conversation

@CSSFrancis

Copy link
Copy Markdown
Member

#3 — SIGABRT at exit on Python 3.13. The stdin pump kept calling readline() after delivering quit. If that read returned while the interpreter was finalizing, 3.13 parks the thread forever holding stdin's buffer lock, and closing stdin aborts the process. The pump now stops reading once it has queued a {"type": "quit"} line, so no read is in flight at shutdown. A cheap substring check runs first, so other lines are not parsed twice. Tests check that nothing after quit is read, and that quit inside a payload doesn't stop the pump. I couldn't reproduce the abort itself: it is timing-dependent and was only seen on Linux CI.

#35 — the backend's exit was reported only when its pipes closed.

  • backend_exited is now also sent on the process's exit event, if close hasn't followed within 1 s, with stdio_open: true. It is sent once, for whichever of spawn error, exit and close comes first.
  • After the Windows backstop's taskkill, its exit status is read. If the backend's output is still open 3 s later, a backend_stuck message is sent with the pid and the kill status.
  • Both messages are typed in renderer/protocol.ts.

Two limits:

  • The held-pipe case can't be built on Windows. Here, Node reports a child's pipes closed as soon as it exits, even while a process it started still writes to them; the venv launcher also takes its interpreter down with it when killed. So the test for that case is skipped on Windows and runs on Linux and macOS CI.
  • Not done: pointing the backstop at the interpreter's own pid, which the issue lists as optional. When the launcher has already exited, taskkill /T on its pid can't reach the interpreter. That needs the backend to report its real pid in ready; left for a follow-up.

Typecheck, 180 unit tests (1 skipped on Windows) and 132 pytest tests pass locally.

Closes #3, closes #35.

- The stdin pump stops reading once it has delivered `quit` (#3). A read
  still in flight when the interpreter shuts down holds stdin's buffer
  lock; Python 3.13 parks that thread forever and closing stdin at exit
  aborts the process.
- backend_exited is reported when the backend process exits, if its
  output has not closed within a second, with stdio_open: true (#35). In
  the packaged layout the interpreter behind the venv launcher can keep
  the pipes open long after the launcher has gone. Reported once,
  whichever of the spawn error, exit and close comes first.
- After the Windows backstop's taskkill, a backend_stuck message (pid,
  kill status) reports a tree whose output is still open 3 s later.
@CSSFrancis
CSSFrancis merged commit 3131f4b into main Nov 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant