Skip to content

🐛 fix(subprocess): stop the backend when a call is interrupted - #332

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
zfz2005:fix/interrupted-backend-cleanup
Oct 27, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
zfz2005:fix/interrupted-backend-cleanup

Conversation

@zfz2005

@zfz2005 zfz2005 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

When a frontend call raised while waiting on the backend, for example on KeyboardInterrupt or SystemExit from a signal handler, the backend process kept running and its output-collection thread kept the interpreter alive until the backend finished on its own. 🛑 The frontend now stops the backend it started and waits for that thread before the original exception reaches the caller.

The cleanup belongs to the frontend's per-call context: on any exit from a call it kills the backend process (a no-op once the process has exited) and joins the thread that drains the backend's pipes. The exception itself propagates unchanged.

Impact

Only the backend process is stopped, not processes it started. If such a child inherits the backend's output pipes and keeps running, the frontend waits for it before the exception reaches the caller; with a child that sleeps 8 seconds, the interrupt surfaced after 8 seconds. Before this change the exception surfaced at once, but the interpreter still waited at exit for both the backend and the child. Stopping a whole process tree stays out of scope.

zfz2005 and others added 2 commits October 25, 2026 18:07
Popen.kill() already returns without signalling once the process has
exited, so the poll() guard repeated it. The test now asserts the one
observable effect, the output thread ending; closed pipes follow from
communicate() returning. Name the parametrized cases and mark the new
locals Final.
@gaborbernat gaborbernat changed the title Clean up the backend process when a frontend call is interrupted 🐛 fix(subprocess): stop the backend when a call is interrupted Oct 27, 2026
@gaborbernat gaborbernat added the bug Something isn't working label Oct 27, 2026

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat
gaborbernat merged commit 2f6d0e0 into tox-dev:main Oct 27, 2026
53 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants