nodejs / nodejs/node

Add passive signal observers

Ouverte
#62,909 2 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

feature request
Langage dominant
JavaScript
Étoiles
122k
Forks
37.3k
Merge moyen
4 j 2 h
PR mergées (30 j)
283

Description

What is the problem this feature will solve?

Node currently exposes signals through process.on('SIGINT') / process.on('SIGTERM'), but that API combines two very different needs:

  • observing that a signal happened
  • taking ownership of shutdown behavior

That coupling creates avoidable ecosystem friction. Many libraries only need best-effort cleanup when a process is interrupted, for example restoring terminal state, showing the cursor again, or stopping a spinner. Today, the only way to do that is to install a real signal handler, which changes global process semantics, suppresses default behavior, and can interfere with app-defined handlers.

What is the feature you are proposing to solve the problem?

Node should add a passive API such as:

process.observeSignal('SIGINT', () => {
	restoreTerminalState();
});

A passive observer would be notified when the signal arrives, but would not count as a handler, would not suppress Node's default behavior, and would not affect app ownership of signal handling. Apps that want to intercept or overrride shutdown would continue to use process.on(...).

This would give Node a clean separation between "tell me this happened" and "I am handling this". It solves a real problem for CLI and terminal libraries, reduces handler conflicts, preserves backward compatibility, and makes signal behavior more predictable across the ecosystem.

What alternatives have you considered?

Considered alternatives:

  1. Reuse process.on() / process.once()
    Rejected because it does not separate observation from handling. Libraries still become real signal handlers and can change global process behavior.

  2. Rely on exit hooks like exit / beforeExit
    Rejected because they are not signal-specific and are too late or inconsistent for cleanup that should happen when the signal is delivered.

  3. Tell libraries to avoid signals entirely
    Rejected because it pushes the problem onto every app and leaves reusable CLI libraries without a clean way to do best-effort cleanup.

  4. Add ordering, priority, or metadata to existing signal handlers
    Rejected because it may reduce conflicts, but it still treats passive observers as active handlers. Th core problem remains.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par examiner la gestion existante des signaux de Node avec process.on('SIGINT') et process.on('SIGTERM'), ainsi que les alternatives exit et beforeExit décrites dans l’issue. Définissez ce qu’un observateur passif doit faire différemment d’un véritable gestionnaire, notamment en préservant le comportement par défaut et la responsabilité définie par l’application. Le travail est considéré comme terminé lorsque l’API proposée et la sémantique de ses signaux sont spécifiées suffisamment clairement pour être implémentées.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, node.js
Domaine
operating-systems
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.