Skip to content

Child keeps running after its client is killed by SIGTERM, SIGHUP or SIGKILL #764

Open

Description

@jscheid

When a Spring 4.7.0 client process ends by "deadly" signals such as SIGTERM, SIGKILL, SIGHUP, the command process spawned by the Spring application will keep running until it finishes on its own, or forever if it waits on something. That can cause problems when it's consuming resources or holding locks.

Minimal repro (tested on Linux):

bin/rails runner 'sleep 60' & sleep 10; kill -TERM $!  # or -HUP, -KILL
sleep 2; ps -eo pid,args | grep '[r]ails_runner'  # still running

SIGINT works as expected but it would be great if other signals were covered as well. It would be useful, for example, when...

  • timeout(1) times out (SIGTERM)
  • an agent subprocess is ended (often SIGTERM then SIGKILL)
  • a terminal window or tab is closed, or an SSH or docker session is lost (SIGHUP)
  • just using plain kill with default args (SIGTERM)

I'd be happy to prepare a PR for it if that's welcome. My proposed fix is to treat unexpected EOF on the client socket as the client's death in Spring::Application#wait and send TERM to the command's process group - that should cover all cases.

EDIT: Actually it would be more accurate to forward termination signals like TERM, HUP and ALRM the same way INT is forwarded, and use EOF as a catch-all for a crash (SEGV and the like, which would be a bit silly to forward) and most importantly KILL (which can't be forwarded).

EDIT: I've also noticed that with orphaned children, spring stop reports success but leaves the server and the application process (that spawned the orphan) running until all orphans have exited. That would be fixed as a side-effect ✨

Activity

  1. fuzzyrichie commented on Nov 24, 2026

    @fuzzyrichie

    We hit this too: a hung spec under timeout 300 bin/rspec … | tail kept the pipeline open overnight, since timeout only ended the client. I've opened #765 following your proposal: TERM/HUP are forwarded once the command runs (not queued during the preload, so timeout still ends a client stuck there), and EOF on the client socket while the command runs sends TERM to its process group, covering KILL and crashes. @jscheid, happy to fold in anything you'd planned, or to close mine if you'd rather send yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions