Skip to content

fix(functions): don't orphan the Python discovery server - #10893

Open
IzaakGough wants to merge 5 commits into
mainfrom
@invertase/fix-issue-10847
Open

fix(functions): don't orphan the Python discovery server#10893
IzaakGough wants to merge 5 commits into
mainfrom
@invertase/fix-issue-10847

Conversation

@IzaakGough

@IzaakGough IzaakGough commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #10847

The Python discovery admin server (serving.py) could survive a deploy: serveAdmin's shutdown logic cleared its force-kill timer immediately after setting it, so the SIGKILL fallback never ran, and it waited on exit/error with no timeout. It also only signalled the shell that runWithVirtualEnv spawns, not the Python process underneath. An orphaned server kept the discovery port bound, so later deploys hung on connect ETIMEDOUT.

Shutdown now escalates properly: /__/quitquitquit with a timeout, then a force-kill of the child's process group (taskkill /T /F on Windows), with an overall cap so a wedged server can never hang the deploy. The child is spawned detached so the whole group can be killed, and is tracked so SIGINT/SIGTERM/SIGHUP and process exit clean it up if the CLI itself goes away, which is what left servers behind on CI cancellation.

The Python delegate's admin server shutdown could never force-kill a
wedged server: the SIGKILL timer was cleared immediately after being
set, the pid it held was the venv shell rather than Python underneath
it, and nothing ran at all when the CLI itself was killed. A stuck
server then left the deploy waiting on an exit event that never came.

Spawn the server detached and kill its process group, bound every wait
in the shutdown path, and force-kill tracked children on SIGINT,
SIGTERM and SIGHUP.

Fixes #10847

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request resolves an issue where the Python discovery admin server was left running after a killed or wedged deploy, causing subsequent deploys to hang. It introduces detached process spawning for the admin server, process group tracking, and a robust shutdown sequence that escalates to force-killing the process group on termination signals or timeouts. The reviewer provided valuable feedback, identifying a potential 15-second hang if the child process exits before shutdown is initiated, and suggesting a guard against zero or negative PIDs in killProcessTree to prevent the CLI from accidentally terminating itself.

Comment thread src/deploy/functions/runtimes/python/index.ts Outdated
Comment thread src/functions/python.ts
Attach the exit/error listeners at spawn time rather than in shutdownAdmin.
Neither event replays, so a discovery server that died before shutdown ran
(a venv that fails to activate, a missing interpreter) left a listener that
could never fire, stalling shutdown for the full 15s timeout, skipping the
untrack, force-killing a reaped pid, and logging a misleading "survived
being force-killed".

Also guard killProcessTree against a zero or negative pid: callers filter
those today, but the function is exported and process.kill(-0, ...) would
signal the CLI's own process group.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Killed deploy orphans the Python discovery server (serving.py); orphans wedge and later deploys hang forever on connect ETIMEDOUT

2 participants