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

Aperta
#764 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
linux, rails, ruby

Direzione di ricerca

Start by reading Spring::Application#wait and the existing SIGINT forwarding path. Reproduce the issue with the Linux shell commands in the report, then trace how the client socket and spawned command process are managed. Done means child processes are cleaned up after the described client signals or socket EOF, and spring stop no longer waits on orphaned children.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 ✨

Lingua principale
Ruby
Stelle
2.8k
Fork
343
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rails/spring

Tutte le issue di rails/spring

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.