-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SIGINT is not handled when a short-lived process is run in watch-mode #51466
Comments
In watch-mode, which executes short-lived scripts, there is a bug where SIGINT or SIGTERM could not terminate the process because the signal handler did not terminate. This change resolves this issue. Fixes: nodejs#51466
Doing CtrlC is correctly terminating the process for me 🤔 |
Ctrl C is terminating the process for me. |
Oh! The Sorry, I had oversimplified the reproduction conditions and made a mistake. We can actually reproduce this by specifying the entry point script in $ vim index.js
$ cat index.js
console.log("test");
$ node --watch-path index.js index.js
(node:1512205) ExperimentalWarning: Watch mode is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
test
Completed running 'test.js'
^C^C^C^C^C^C^C Also, this behavior only seems to work on Linux. Could not reproduce on Mac. |
@azrsh Could re-produce the issue at v22.0.0-pre. However, I found your use of --watch-path is wrong. The correct command should be "node --watch-path=./ index.js". If you run my command, It should work as fine. Though, I could see a possible new issue on flag parsing. For example, not correct option on --watch-path should be stopped. |
In my environment, the command certainly works fine. Does it mean that specifying a file instead of a directory in |
Version
v20.11.0
Platform
Linux hostname 6.5.7-arch1-1 #\1 SMP PREEMPT_DYNAMIC Tue, 10 Oct 2023 21:10:21 +0000 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
index.js
.After following the above steps, you will no longer be able to terminate the Node.js process in watch-mode with
SIGINT
orSIGTERM
.How often does it reproduce? Is there a required condition?
If you follow the steps, it will always reproduce.
What is the expected behavior? Why is that the expected behavior?
A Node.js process in watch-mode will be terminated if we send
SIGINT
orSIGTERM
to the process, such as withCtrl + C
.What do you see instead?
I input Ctrl + C but the input is ignored.
Additional information
Mechanism of this behavior
The cause of this behavior is the
killAndWait
function located in/lib/internal/main/watch_mode.js:69
.Node.js process in watch-mode triggers a signal handler when it receives SIGINT or SIGTERM. In this signal handler, the
killAndWait
function is called as shown below.node/lib/internal/main/watch_mode.js
Line 134 in c25878d
At this time, since the argument
force
of thekillAndWait
function is set totrue
, processing continues without satisfying the condition in the code path below of thekillAndWait
function.node/lib/internal/main/watch_mode.js
Lines 74 to 76 in c25878d
As a result, the
killAndWait
function will wait for a process that has already terminated to terminate. In other words, the wait never ends.node/lib/internal/main/watch_mode.js
Lines 77 to 79 in c25878d
My proposed modifications
Modify the
killAndWait
function so that ifexited
istrue
, return thekillAndWait
function regardless of the value of the argumentforce
.If you accept this modification, I can create a PR!
Thank you!
The text was updated successfully, but these errors were encountered: