Skip to content

rpc: exit JS server when parent connection closes#7652

Merged
jkschneider merged 1 commit into
mainfrom
shutdown-on-cancel
May 12, 2026
Merged

rpc: exit JS server when parent connection closes#7652
jkschneider merged 1 commit into
mainfrom
shutdown-on-cancel

Conversation

@jkschneider
Copy link
Copy Markdown
Member

Summary

  • When the host JVM is SIGKILLed, its shutdown hook never runs and RewriteRpcProcess.shutdown() never invokes process.destroy() on spawned RPC subprocesses. The Python (stdin EOF → break), Go (io.EOF → break), and C# (JsonRpc.Completion) servers all exit naturally in that case; the JS server did not, because connection.onClose only logged — and Pyroscope (or any other event-loop ref-holder) kept the Node process alive, orphaning it on the host.
  • Converge SIGINT, SIGTERM, and connection.onClose on a single shutdown() (with a re-entry guard) that performs temp-dir + workspace cleanup and exits with code 0. This closes the orphan-on-parent-SIGKILL hazard while keeping the existing signal-handler cleanup behavior.

Test plan

  • npm run typecheck passes
  • Spawn the JS RPC server, SIGKILL the parent (or close its stdin), confirm the JS process exits within a second instead of lingering
  • Verify recipe temp dir cleanup still runs on SIGINT/SIGTERM

When the host JVM is SIGKILLed, its shutdown hook never fires, so
RewriteRpcProcess.shutdown() doesn't call process.destroy() on the
JS subprocess. The Python and Go servers self-terminate on stdin EOF;
C# exits when JsonRpc.Completion resolves. But the JS server's
connection.onClose handler only logged — and Pyroscope (or any other
ref-holder) kept the Node event loop alive, orphaning the process.

Wire connection.onClose to a shared shutdown() that also runs on
SIGINT/SIGTERM, so all three exit paths converge on the same cleanup
(recipe temp dir + DependencyWorkspace) and exit with code 0.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 11, 2026
@jkschneider jkschneider merged commit d962cd1 into main May 12, 2026
1 check passed
@jkschneider jkschneider deleted the shutdown-on-cancel branch May 12, 2026 11:34
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant