Open nakamorichi opened 8 years ago
Would it be an issue because of the way we spawn processes?
I don't know if I have to customize something on this code segments,
{detached: true
should get rid of this error but it is not available for cluster.
interesting, maybe @ThisIsMac47 will have a look at this on the next weeks
After testing, the detached option doesnt hide popups on Windows, i think that nodejs spawn a shell to spawn the process. I will investigate more in the next days.
Okay so :
If you get any popup apart of cluster mode, respond to this issue to report it, i will investigate for each one.
Because we can't get detached: true
in cluster?
They use the function fork, we can use detached: true
only with spawn.
Yes ok so if that's the main reason, the only solution is to port cluster into pm2 instead of using the nodejs cluster. Did you try a simple cluster implementation without pm2 to see if it pops up too?
I wasnt able to reproduce with a simple cluster implementation, this might coming from the fact that we are a spawning a child from a forked child or something like this. We manage to delete the popups in cluster mod by rewriting the implementation on the branch of a forked cluster implementation, we will talk about how include this into future release of pm2.
Is this issue fixed or any workaround available? I have faced the same issue when using cluster mode with watch option. The node window opens multiple time when saving the file.
@ajithr No, like i said, the problem come from nodeJs implementation of the cluster mode. I suggest you to develop in fork mode.
For me what has been working quite well is to use --no-daemon
.
However, if pm2 was previously started as a daemon process, then this flag has no effect and the popups keep appearing, unless I run pm2 kill
.
@gustavohenke I followed your instructions, but it did not work for me. I am using pm2 2.0.19 on Windows 8.1 and I still get a popup window everytime I use child_process.exec()
@centigrade-thomas-becker The fact a popup is spawning when you call child_process.exec
isn't coming from pm2, it come from the system of spawning a child process of node itself, you may add detached: true
to the spawning config and it will not spawn any popup.
The problem of #2182 is that in cluster mode, we can't control how the process are spawn, so we can't add this options to hide the popup under windows.
@centigrade-thomas-becker you should try to use child_process.spawn
and add a {detached: true}
option.
I wanted to share what I did to overcome the popup.
Initially I will npm start
my app that starts pm2
as well, then I will do pm2 stop all
immediately. After that when I again do npm start
, it just pops up only once and never again.
Do we have any updates on this for a proper implementation that will patch this issue?
I use PM2 when locally developing. It's becoming an issue to run pm2 kill
after every script run. Consoles interrupting me when working is not welcome.
Try this,
1) npm start
your project as usual (pop-up's keep on coming up)
2) Stop the project (Ctrl-C
)
3) pm2 delete <project-name>
4) Again npm start
(this time it stops popping up)
Hope it works!
I use the process json file to launch my pm2 instances so I do not believe that will work for me. On Fri, 31 Mar 2017 at 1:07 pm, Raghav Manikandan notifications@github.com wrote:
Try this,
- npm start your project as usual (pop-up's keep on coming up)
- Stop the project (Ctrl-C)
- pm2 delete
- Again npm start (this time it stops popping up)
Hope it works!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Unitech/pm2/issues/2182#issuecomment-290694966, or mute the thread https://github.com/notifications/unsubscribe-auth/AQFo-gSTsM1ff6b76yV4Qj20hfUV-uF4ks5rrOyHgaJpZM4Ijsqx .
Any fix to this? Just asking 😄
I wanted to share what I did to overcome the popup. Initially I will npm start my app that starts pm2 as well, then I will do pm2 stop all immediately. After that when I again do npm start, it just pops up only once and never again.
@mswaminath Can you please post your pm2 config, and how you spawn your child processes?
Any permanent solution for this ??
This issue is especially terrible if you have autorestart enabled, and something causes your script to crash after it loads (I accidentally renamed a file the script frequently reads from). Then all hell breaks loose! Windows are spawning and crashing so fast, I couldn't type or click on anything since the windows spawn in the foreground with focus. It's completely ignoring "max_restarts" and "restart_delay" (i'm guessing these don't apply to clusters). I literally had no choice but to hard reset my computer.
Wow it feels like I just won a game of solitaire
So for production applications it is imperative to take the weight off the single event loop by forking a few processes to balance the load. Well, fork() does not take a detached option, and nor should it. Once the primary process fails the child processes will be closed subsequently, allowing pm2 to respawn the parent which will re-fork children, while keeping only 1 instance of each process and maintaining the IPC pipe between them. This is quite simple and the forking nature of the node parent process is beautiful in this regard in my opinion.
At this point our only option is to use pm2 to create 4 actual and separate node apps. This may work, maybe. I have no idea how we will accomplish any kind of IPC messages back and forth from the processes considering there is no parent process to route the messages.
In other words, pm2 for production purposes on windows is currently not working. I will mention that if anyone can find time to resolve this issue, we will be happy to finance your hourly work in the name of getting this problem solved ASAP.
Thank you.
I have found a very simple fix that am using now for development,
instances: 1
linepm2 delete <project-name>
(one time process)npm start
Then you will see the magic, but I suggest to use this only for development.
We aren't using a config file. Our master process forks into sub-processes. Will this work for that?
Any updates on this? I run multiple instances so cannot write off instance support.
I've opened this ticket with nodejs: https://github.com/nodejs/node/issues/15217
Would be great if everyone watching this ticket went and upvoted and shared this one. Really it seems like something that wouldn't be high impact for them to fix!
I think this is occurring for me on exec processes called by PM2 process management. I am using fork mode. What do you think, does this occur for subprocesses started with exec even with fork?
Any updates?
child_process.spawn::windowsHide
option is already awailable:
https://github.com/nodejs/node/issues/15217#ref-pullrequest-267864790
https://github.com/Unitech/pm2/pull/3255 https://github.com/nodejs/node/issues/15217#ref-pullrequest-267864790 thanks to @soyuka @milichev @cjihrig
May you try development branch @milichev ?
Is it possible to get this a little earlier than release?
Installed with no success. The same console fireworks on each watched file change -(
node -v
v8.9.0
yarn global add https://github.com/Unitech/pm2@development
Any update?
It was fixed for me
@FireController1847 Not for me I think.
git clone git@github.com:Unitech/pm2.git
cd pm2
git checkout development
npm link
cd \test
pm2 start test.js -i 2
Still got 2 black console windows poped up!
node --version v9.2.0 pm2 --version 2.8.0
I'm on Window 10.
Is there any wrong with my setup?
Ah, actually, you're right. The window does popup. Nevermind.
Unless i missed something, God.nodeApp(in lib/God/ClusterMode.js) called cluster.fork, which has no windowsHide parameter at all!? Dead end!
I got a hacky solution
diff --git a/lib/God.js b/lib/God.js
index bf3bedda..61178584 100644
--- a/lib/God.js
+++ b/lib/God.js
@@ -15,7 +15,7 @@
******************************/
var semver = require('semver');
-var cluster = require('cluster');
+var cluster = require('./cluster_hack');
var numCPUs = require('os').cpus() ? require('os').cpus().length : 1;
var path = require('path');
var EventEmitter2 = require('eventemitter2').EventEmitter2;
diff --git a/lib/God/ClusterMode.js b/lib/God/ClusterMode.js
index 3a1185a3..af9bf43a 100644
--- a/lib/God/ClusterMode.js
+++ b/lib/God/ClusterMode.js
@@ -10,7 +10,7 @@
* @author Alexandre Strzelewicz <as@unitech.io>
* @project PM2
*/
-var cluster = require('cluster');
+var cluster = require('../cluster_hack');
var cst = require('../../constants.js');
var Utility = require('../Utility.js');
var pkg = require('../../package.json');
@@ -49,7 +49,7 @@ module.exports = function ClusterMode(God) {
// { "args": ["foo", "bar"], "env": { "foo1": "bar1" }} will be parsed to
// { "args": "foo, bar", "env": "[object Object]"}
// So we passing a stringified JSON here.
- clu = cluster.fork({pm2_env: JSON.stringify(env_copy), windowsHide: true});
+ clu = cluster.fork({pm2_env: JSON.stringify(env_copy), pm2_windowsHide: true});
} catch(e) {
God.logAndGenerateError(e);
return cb(e);
diff --git a/lib/cluster_hack.js b/lib/cluster_hack.js
new file mode 100644
index 00000000..c1cfd86b
--- /dev/null
+++ b/lib/cluster_hack.js
@@ -0,0 +1,18 @@
+var child_process = require('child_process');
+var oldFork = child_process.fork;
+child_process.fork = function () {
+ var pos = 1;
+ if (pos < arguments.length && Array.isArray(arguments[pos]))
+ pos++;
+ if (pos < arguments.length && arguments[pos] != null
+ && typeof arguments[pos] === 'object'
+ && arguments[pos].env && arguments[pos].env.pm2_windowsHide) {
+ arguments[pos].windowsHide = true;
+ arguments[pos].silent = true;
+ }
+ return oldFork.apply(this, arguments);
+};
+var cluster = require('cluster');
+child_process.fork = oldFork;
+
+module.exports = cluster;
But still get black windows flashing when pm2 stop x
pm2 kill
pm2 update
...
edit: I make a fork, toddwong/pm2@dc184e9ef76badbb565d9d61f6d39d4dda712db5
This should be fixed in nodejs then no?
@soyuka Not sure, but I've filed a feature request nodejs/node#17370
But the black windows during pm2 stop x
etc. should be address in pm2 I think.
When using fork
with watch
activated, a black window flashes everytime a change is detected.
Is this normal behavior?
It seems is almost done https://github.com/nodejs/node/pull/17412
Meanwhile, if this helps someone: pm2@2.2.1
is the last version that doesn't show pop-ups for me on win7, fork
mode (above that, it doesn't matter if I run fork
mode or cluster
, it always shows popups).
Should work now, please try latest pm2 published:
$ npm install pm2 -g
$ pm2 update
Unfortunately continues spawning these windows 😞
Node: v9.4.0 OS: Windows 10 pm2: v2.9.2
Command: pm2 start app.js -i max
terminal: tested in git-bash
, cmd
and powershell
The server script:
const http = require("http");
const server = http.createServer(handler);
const port = 4875;
server.listen(port, () => {
console.log("Listening at port %d", port);
});
function handler(req, res) {
res.end("Holita desde Node.js");
}
How do I disable the popup windows that pm2 generates in Windows 10 when starting, restarting or reloading a Node.js app? From the perspective of rapid server-side development, this is very annoying...