cluster: support windowsHide option for workers#17412
cluster: support windowsHide option for workers#17412toddwong wants to merge 3 commits intonodejs:masterfrom
Conversation
bnoordhuis
left a comment
There was a problem hiding this comment.
LGTM with a couple of comments about the test.
There was a problem hiding this comment.
Call cstdout.setEncoding('utf8'), then you don't have to .toString('utf8') below.
There was a problem hiding this comment.
Yeah, you are right, cstdout.setEncoding('utf8') make more sense here. Just deal too much binary data these days :D .
There was a problem hiding this comment.
You don't have to specify 'utf8' if you're writing a string, that's the default encoding.
There was a problem hiding this comment.
I wasn't aware of that...
There was a problem hiding this comment.
Can you explain why you call .pause() here?
There was a problem hiding this comment.
The stdin keeps the worker from exiting. That's the only way I know to get rid of it.
|
Shouldn't the test actually check that the console window doesn't exist somehow (e.g. using Powershell)? |
|
Also, the test could probably be skipped on non-Windows platforms. |
|
I'd say it's good to test that |
There was a problem hiding this comment.
It doesn't really matter, just curious why you used a function here but arrow functions everywhere else.
There was a problem hiding this comment.
My bad. A little careless. I wasn't expecting the stdin would block the process from exiting at the beginning, and put the disconnect handler a little later, and not notice the coding style difference.
|
@mscdex I must confess that this test is just for "formally"(sorry about my English, can't find a proper word...) completeness according to the PR requirements (tests and/or benchmarks are included). Actually, I don't know how to automatically test it at all, and very interested in advises. @bnoordhuis So my test actually useful I think. PS: Thanks for reviewing. |
|
Just polished the test code a little bit according to the above reviews |
bnoordhuis
left a comment
There was a problem hiding this comment.
LGTM, thanks. CI: https://ci.nodejs.org/job/node-test-pull-request/11845/
If there is a way to test with PS that the windows aren't actually created that would be even more awesome, but I have no idea how you'd test that.
|
@bnoordhuis Just checked "test/parallel/test-child-process-windows-hide.js" and got some inspiration. See the commit 242d80c . The idea is that, we just make sure the windowsHide option is passed to the underlying child_process.fork function correctly. And child_process.fork will make sure it passed to libuv finally. And libuv may do the real test for us (Not sure if/how it does, though). |
|
What @mscdex was getting at is using some powershell-fu to check if the worker has a console window associated with it. I'm by no means a PS guru but I expect it would look something like this: const output = child_process.execSync(
`powershell -ExecutionPolicy Unrestricted -NoProfile -c ` +
`"Get-Process -Id ${worker.process.pid} | where ..."`)
.toString('utf8');Where |
No, libuv just passes it on to the OS. |
|
@bnoordhuis Just checked, there is a MainWindowHandle property. But there is another problem, the console windows won't be there for service processes even if they are spawned with |
|
I'm reasonably sure the CI runs tests as a regular process and user. |
|
@bnoordhuis @mscdex Added the fancy PowerShell thing! 😃 |
| process.send({ type: 'workerOnline' }); | ||
|
|
||
| let output = '0'; | ||
| if (process.platform === 'win32') |
There was a problem hiding this comment.
Braces please for multi-line bodies.
bnoordhuis
left a comment
There was a problem hiding this comment.
One suggestion, otherwise nice work.
|
|
||
| let patchedFork = child_process.fork; | ||
| child_process.fork = (...args) => patchedFork.apply(this, args); | ||
| const cluster = require('cluster'); |
There was a problem hiding this comment.
You can get rid of the monkey-patch now because ultimately it doesn't how matter how the option is passed down, as long as the observable effect is the same.
Presumably the child_process.spawn() call can go too? I admit I don't quite understand why you run the tests in a child process.
There was a problem hiding this comment.
I keep the monkey-patch just in case some one run the tests on other platforms or in a windows service session. Not sure if this is necessary or practically useful.
It seems Windows only allocate a new console window for an attaching process spawned by a detached process.
If process D is spawned by process C with detached: true , and process W is spawned by process D with detached: false, W will get a new black console window popped up.
if D is spawned by C with detached: false or W is spawned by D with detached: true, no console window will pop up for W.
C = Command, D = Daemon, W = worker, practically.
That's why the test need to be run in a (detached) child process.
There was a problem hiding this comment.
I keep the monkey-patch just in case some one run the tests on other platforms or in a windows service session. Not sure if this is necessary or practically useful.
Neither, I'd say. :-)
Can you add a comment to the test that explains why it spawns a child process first? I get it now from your explanation but it's not obvious from just looking at the code.
There was a problem hiding this comment.
Sure, i'll add the comment, and remove the monkey-patch thing.
|
@mscdex @bnoordhuis @cjihrig would you mind to take another look? It seems like all comments got addressed. |
|
Thanks, guys. Sorry I forgot leave a message for the last commit. |
|
Hi, guys, It's been a while. Would this be landed any soon? |
|
Sorry for the delay. New CI because the old one is inaccessible and I've added the 'ready' label. |
|
Thanks! |
|
Should this have been semver minor? |
Notable Changes:
* async_hooks:
- rename PromiseWrap.parentId (Ali Ijaz Sheikh)
#18633
- remove runtime deprecation (Ali Ijaz Sheikh)
#19517
- deprecate unsafe emit{Before,After} (Ali Ijaz Sheikh)
#18513
* cluster:
- add cwd to cluster.settings (cjihrig)
#18399
- support windowsHide option for workers (Todd Wong)
#17412
* crypto:
- allow passing null as IV unless required (Tobias Nießen)
#18644
* deps:
- upgrade npm to 6.2.0 (Kat Marchán)
#21592
- upgrade libuv to 1.19.2 (cjihrig)
#18918
- Upgrade node-inspect to 1.11.5 (Jan Krems)
#21055
* fs,net:
- support as and as+ flags in stringToFlags() (Sarat Addepalli)
#18801
- emit 'ready' for fs streams and sockets (Sameer Srivastava)
#19408
* http, http2:
- add options to http.createServer() (Peter Marton)
#15752
- add 103 Early Hints status code (Yosuke Furukawa)
#16644
- add http fallback options to .createServer (Peter Marton)
#15752
* n-api:
- take n-api out of experimental (Michael Dawson)
#19262
* perf_hooks:
- add warning when too many entries in the timeline (James M Snell)
#18087
* src:
- add public API for managing NodePlatform (Cheng Zhao)
#16981
- allow --perf-(basic-)?prof in NODE\_OPTIONS (Leko)
#17600
- node internals' postmortem metadata (Matheus Marchini)
#14901
* tls:
- expose Finished messages in TLSSocket (Anton Salikhmetov)
#19102
* **trace_events**:
- add file pattern cli option (Andreas Madsen)
#18480
* util:
- implement util.getSystemErrorName() (Joyee Cheung)
#18186
PR-URL: #21593
Notable Changes:
* async_hooks:
- rename PromiseWrap.parentId (Ali Ijaz Sheikh)
nodejs#18633
- remove runtime deprecation (Ali Ijaz Sheikh)
nodejs#19517
- deprecate unsafe emit{Before,After} (Ali Ijaz Sheikh)
nodejs#18513
* cluster:
- add cwd to cluster.settings (cjihrig)
nodejs#18399
- support windowsHide option for workers (Todd Wong)
nodejs#17412
* crypto:
- allow passing null as IV unless required (Tobias Nießen)
nodejs#18644
* deps:
- upgrade npm to 6.2.0 (Kat Marchán)
nodejs#21592
- upgrade libuv to 1.19.2 (cjihrig)
nodejs#18918
- Upgrade node-inspect to 1.11.5 (Jan Krems)
nodejs#21055
* fs,net:
- support as and as+ flags in stringToFlags() (Sarat Addepalli)
nodejs#18801
- emit 'ready' for fs streams and sockets (Sameer Srivastava)
nodejs#19408
* http, http2:
- add options to http.createServer() (Peter Marton)
nodejs#15752
- add 103 Early Hints status code (Yosuke Furukawa)
nodejs#16644
- add http fallback options to .createServer (Peter Marton)
nodejs#15752
* n-api:
- take n-api out of experimental (Michael Dawson)
nodejs#19262
* perf_hooks:
- add warning when too many entries in the timeline (James M Snell)
nodejs#18087
* src:
- add public API for managing NodePlatform (Cheng Zhao)
nodejs#16981
- allow --perf-(basic-)?prof in NODE\_OPTIONS (Leko)
nodejs#17600
- node internals' postmortem metadata (Matheus Marchini)
nodejs#14901
* tls:
- expose Finished messages in TLSSocket (Anton Salikhmetov)
nodejs#19102
* **trace_events**:
- add file pattern cli option (Andreas Madsen)
nodejs#18480
* util:
- implement util.getSystemErrorName() (Joyee Cheung)
nodejs#18186
PR-URL: nodejs#21593
Notable Changes:
* async_hooks:
- rename PromiseWrap.parentId (Ali Ijaz Sheikh)
#18633
- remove runtime deprecation (Ali Ijaz Sheikh)
#19517
- deprecate unsafe emit{Before,After} (Ali Ijaz Sheikh)
#18513
* cluster:
- add cwd to cluster.settings (cjihrig)
#18399
- support windowsHide option for workers (Todd Wong)
#17412
* crypto:
- allow passing null as IV unless required (Tobias Nießen)
#18644
* deps:
- upgrade npm to 6.4.1 (Kat Marchán)
#22591
- upgrade libuv to 1.19.2 (cjihrig)
#18918
- Upgrade node-inspect to 1.11.5 (Jan Krems)
#21055
* fs,net:
- support as and as+ flags in stringToFlags() (Sarat Addepalli)
#18801
- emit 'ready' for fs streams and sockets (Sameer Srivastava)
#19408
* http, http2:
- add options to http.createServer() (Peter Marton)
#15752
- add 103 Early Hints status code (Yosuke Furukawa)
#16644
- add http fallback options to .createServer (Peter Marton)
#15752
* n-api:
- take n-api out of experimental (Michael Dawson)
#19262
* perf_hooks:
- add warning when too many entries in the timeline (James M Snell)
#18087
* src:
- add public API for managing NodePlatform (Cheng Zhao)
#16981
- allow --perf-(basic-)?prof in NODE\_OPTIONS (Leko)
#17600
- node internals' postmortem metadata (Matheus Marchini)
#14901
* tls:
- expose Finished messages in TLSSocket (Anton Salikhmetov)
#19102
* **trace_events**:
- add file pattern cli option (Andreas Madsen)
#18480
* util:
- implement util.getSystemErrorName() (Joyee Cheung)
#18186
PR-URL: #21593
Notable Changes:
* async_hooks:
- rename PromiseWrap.parentId (Ali Ijaz Sheikh)
#18633
- remove runtime deprecation (Ali Ijaz Sheikh)
#19517
- deprecate unsafe emit{Before,After} (Ali Ijaz Sheikh)
#18513
* cluster:
- add cwd to cluster.settings (cjihrig)
#18399
- support windowsHide option for workers (Todd Wong)
#17412
* crypto:
- allow passing null as IV unless required (Tobias Nießen)
#18644
* deps:
- upgrade npm to 6.2.0 (Kat Marchán)
#21592
- upgrade libuv to 1.19.2 (cjihrig)
#18918
- Upgrade node-inspect to 1.11.5 (Jan Krems)
#21055
* fs,net:
- support as and as+ flags in stringToFlags() (Sarat Addepalli)
#18801
- emit 'ready' for fs streams and sockets (Sameer Srivastava)
#19408
* http, http2:
- add options to http.createServer() (Peter Marton)
#15752
- add 103 Early Hints status code (Yosuke Furukawa)
#16644
- add http fallback options to .createServer (Peter Marton)
#15752
* n-api:
- take n-api out of experimental (Michael Dawson)
#19262
* perf_hooks:
- add warning when too many entries in the timeline (James M Snell)
#18087
* src:
- add public API for managing NodePlatform (Cheng Zhao)
#16981
- allow --perf-(basic-)?prof in NODE\_OPTIONS (Leko)
#17600
- node internals' postmortem metadata (Matheus Marchini)
#14901
* tls:
- expose Finished messages in TLSSocket (Anton Salikhmetov)
#19102
* **trace_events**:
- add file pattern cli option (Andreas Madsen)
#18480
* util:
- implement util.getSystemErrorName() (Joyee Cheung)
#18186
PR-URL: #21593
Notable Changes:
* async_hooks:
- rename PromiseWrap.parentId (Ali Ijaz Sheikh)
#18633
- remove runtime deprecation (Ali Ijaz Sheikh)
#19517
- deprecate unsafe emit{Before,After} (Ali Ijaz Sheikh)
#18513
* cluster:
- add cwd to cluster.settings (cjihrig)
#18399
- support windowsHide option for workers (Todd Wong)
#17412
* crypto:
- allow passing null as IV unless required (Tobias Nießen)
#18644
* deps:
- upgrade npm to 6.2.0 (Kat Marchán)
#21592
- upgrade libuv to 1.19.2 (cjihrig)
#18918
- Upgrade node-inspect to 1.11.5 (Jan Krems)
#21055
* fs,net:
- support as and as+ flags in stringToFlags() (Sarat Addepalli)
#18801
- emit 'ready' for fs streams and sockets (Sameer Srivastava)
#19408
* http, http2:
- add options to http.createServer() (Peter Marton)
#15752
- add 103 Early Hints status code (Yosuke Furukawa)
#16644
- add http fallback options to .createServer (Peter Marton)
#15752
* n-api:
- take n-api out of experimental (Michael Dawson)
#19262
* perf_hooks:
- add warning when too many entries in the timeline (James M Snell)
#18087
* src:
- add public API for managing NodePlatform (Cheng Zhao)
#16981
- allow --perf-(basic-)?prof in NODE\_OPTIONS (Leko)
#17600
- node internals' postmortem metadata (Matheus Marchini)
#14901
* tls:
- expose Finished messages in TLSSocket (Anton Salikhmetov)
#19102
* **trace_events**:
- add file pattern cli option (Andreas Madsen)
#18480
* util:
- implement util.getSystemErrorName() (Joyee Cheung)
#18186
PR-URL: #21593
Notable Changes:
* async_hooks:
- rename PromiseWrap.parentId (Ali Ijaz Sheikh)
#18633
- remove runtime deprecation (Ali Ijaz Sheikh)
#19517
- deprecate unsafe emit{Before,After} (Ali Ijaz Sheikh)
#18513
* cluster:
- add cwd to cluster.settings (cjihrig)
#18399
- support windowsHide option for workers (Todd Wong)
#17412
* crypto:
- allow passing null as IV unless required (Tobias Nießen)
#18644
* deps:
- upgrade npm to 6.2.0 (Kat Marchán)
#21592
- upgrade libuv to 1.19.2 (cjihrig)
#18918
- Upgrade node-inspect to 1.11.5 (Jan Krems)
#21055
* fs,net:
- support as and as+ flags in stringToFlags() (Sarat Addepalli)
#18801
- emit 'ready' for fs streams and sockets (Sameer Srivastava)
#19408
* http, http2:
- add options to http.createServer() (Peter Marton)
#15752
- add 103 Early Hints status code (Yosuke Furukawa)
#16644
- add http fallback options to .createServer (Peter Marton)
#15752
* n-api:
- take n-api out of experimental (Michael Dawson)
#19262
* perf_hooks:
- add warning when too many entries in the timeline (James M Snell)
#18087
* src:
- add public API for managing NodePlatform (Cheng Zhao)
#16981
- allow --perf-(basic-)?prof in NODE\_OPTIONS (Leko)
#17600
- node internals' postmortem metadata (Matheus Marchini)
#14901
* tls:
- expose Finished messages in TLSSocket (Anton Salikhmetov)
#19102
* **trace_events**:
- add file pattern cli option (Andreas Madsen)
#18480
* util:
- implement util.getSystemErrorName() (Joyee Cheung)
#18186
PR-URL: #21593
Fixes: #17370
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
cluster