Add passive signal observers
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 272
Mô tả
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:
-
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. -
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. -
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. -
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách xem xét cơ chế xử lý signal hiện có của Node với process.on('SIGINT') và process.on('SIGTERM'), cùng với các lựa chọn thay thế exit và beforeExit được mô tả trong issue. Xác định một passive observer phải thực hiện khác với một handler thực sự như thế nào, bao gồm việc giữ nguyên hành vi mặc định và quyền sở hữu do ứng dụng định nghĩa. Công việc được xem là hoàn tất khi API được đề xuất và ngữ nghĩa signal của nó được đặc tả đủ rõ ràng để triển khai.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- operating-systems
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100