-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Forked process cannot capture any process events "exit", "SIGINT", "SIGTERM" #3467
Comments
It could be invalid. Close for now. |
I definitely need this too e.g an option to prevent pm2 to treekill all the detached processes spawned by my nodejs application on Windows. My nodejs application spawns processes this way: const childProc = spawn(processPath, appConfig.binArgs,
{
stdio: "ignore",
detached: true,
cwd: appInstallDir
}); This is explained on options.detached of the nodejs child process documentation
An option for the pm2 fork_mode could allow to change the options.stdio here) to "ignore": try {
var options = {
env : pm2_env,
detached : true,
cwd : pm2_env.pm_cwd || process.cwd(),
stdio : 'ignore'
}
if (typeof(pm2_env.windowsHide) === "boolean") {
options.windowsHide = pm2_env.windowsHide;
} else {
options.windowsHide = true;
}
if (pm2_env.uid) {
options.uid = pm2_env.uid
}
if (pm2_env.gid) {
options.gid = pm2_env.gid
}
var cspr = spawn(command, args, options);
} catch(e) {
God.logAndGenerateError(e);
return cb(e);
} |
Environment: Windows 7 (x64) + Node 9.5.0
The Problem
CODE: app.js
If I run
node app.js
and then press CTRL+C, I can seeSIGINT, byebye
.But if I run the code with PM2
Related messages are not appear in log. It seems that none of these events (
exit
,SIGINT
andSIGTERM
) are called. It seems the nodejs process is not killed gracefully. (Correct me if I'm wrong)My Investigation and Questions
I know Windows does not handle posix signals. But we still need to find a way to properly kill forked process, right? If a nodejs process cannot be killed gracefully, how can we make sure other non nodejs process can be killed well?
After some investigation, I found this question on SO. The trick is
{detached:true, stdio: 'ignore'}
readline
interface in app.js and manually send aprocess.emit('SIGINT') in
close` event.Here is how PM2 forks a process.
As you can see, stdio is
pipe
, notignore
. I need to understand can PM2 developer changepipe
toignore
so that forked process can be killed gracefully?Workaround
As I only use PM2 as a pure process manager, no monitoring tasks, no deploy tasks. So for the time being, I made some small changes without having a serious problem. Here is what I have done:
I dont think my patch is a good patch. Help is needed.
The text was updated successfully, but these errors were encountered: