npm wrapper: SIGTERM/SIGINT orphans yaci-cli and leaves a stale PID file

Aperta
#220 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@satran004 ci sta già lavorando.

Dal 10/11/2026.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
linux, macos, node.js, shell
Ambito
cli, devtools

Direzione di ricerca

Start in start.mjs, where the npm wrapper spawns yaci-cli and registers its close handler that removes ~/.yaci-cli/yaci-cli.pid; the signal forwarding belongs next to that spawn. Reproduce by running yaci-devkit up, sending SIGTERM to the wrapper PID, and checking with ps that the children are gone and the PID file is removed. Done when the wrapper forwards SIGINT, SIGTERM and SIGHUP and the stale PID file check verifies the process is still yaci-cli before killing it.

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

Descrizione

Problem

The npm wrapper (start.mjs) spawns yaci-cli but installs no signal handlers. When the wrapper process alone is signalled, which is what a script, test runner or process manager does when it stops the yaci-devkit PID it started:

  1. Node exits right away and yaci-cli is orphaned (reparented to PID 1), still running the node, submit-api, ogmios and yaci-store.
  2. The close handler that removes ~/.yaci-cli/yaci-cli.pid never runs, so the PID file is left behind.
  3. On the next yaci-devkit run, killProcessTree sends SIGTERM to the children of the PID in that file and SIGKILL to the PID itself, without checking that it is still yaci-cli. If the PID has been reused, an unrelated process gets killed.

An interactive Ctrl-C mostly works, because the terminal sends SIGINT to the whole foreground process group, yaci-cli included. The problem shows up when there is no terminal, e.g. in CI or in a just test / npm test script that starts a throwaway devnet and stops it afterwards.

This looks like one of the edge cases mentioned in #94.

Reproduce

Linux x64, @bloxbean/yaci-devkit 0.12.0, Node 24:

yaci-devkit up --enable-yaci-store </dev/null >up.log 2>&1 &
W=$!
# wait until http://localhost:8080/api/v1/blocks/latest responds
kill -TERM "$W"
sleep 5
ps -ef | grep -E 'yaci-cli|cardano-node|ogmios|yaci-store'   # all still running
cat ~/.yaci-cli/yaci-cli.pid                                 # still there

Observed after the SIGTERM:

PID      PPID     COMMAND
1607653  1        yaci-cli
1607821  1607820  cardano-node
1607837  1607834  cardano-submit-
1607884  1607880  ogmios
1607899  1607653  yaci-store-n2c
pidfile: 1607653

Suggested fix

In start.mjs:

  • Forward SIGINT, SIGTERM and SIGHUP to the child and keep waiting for it, so the existing close handler removes the PID file and exits with the child's code:

    for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) {
        process.on(sig, () => child.kill(sig));
    }
    
  • Before killing the PID from a leftover PID file, check that the process is still yaci-cli (e.g. ps -p <pid> -o comm= on Linux and macOS) and only remove the file otherwise.

A non-interactive way to stop a running devkit (say yaci-devkit down) would also help scripts that started it in another process.

Workaround

We currently start the devkit in its own process group (setsid) and signal the whole group on teardown, then remove the PID file if its PID is no longer alive.

Lingua principale
Java
Stelle
70
Fork
21
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 bloxbean/yaci-devkit

Tutte le issue di bloxbean/yaci-devkit

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.