Skip to content
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

child_process: add windowsHide option #15380

Merged
merged 1 commit into from
Oct 16, 2017
Merged

child_process: add windowsHide option #15380

merged 1 commit into from
Oct 16, 2017

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Sep 13, 2017

This commit exposes the UV_PROCESS_WINDOWS_HIDE flag in Node as a windowsHide option to the child_process methods. The option is only applicable to Windows, and is ignored elsewhere.

This still needs docs, which I'll write if:

  • Someone verifies that this actually works on Windows.
  • We agree that we want this documented. windowsVerbatimArguments, for example, is not.

Fixes: #15217

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

child_process

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Sep 13, 2017
@mscdex mscdex added child_process Issues and PRs related to the child_process subsystem. windows Issues and PRs related to the Windows platform. labels Sep 13, 2017
// options.windowsHide
Local<String> windows_hide_key = env->windows_hide_string();

if (js_options->Get(windows_hide_key)->IsTrue()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ideally use the overload that takes a Local<Context> but OTOH, all the other options don't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis I'll submit a follow up PR to switch all of the options to use the context.

@@ -777,6 +777,11 @@ int SyncProcessRunner::ParseOptions(Local<Value> js_value) {
if (js_options->Get(env()->detached_string())->BooleanValue())
uv_process_options_.flags |= UV_PROCESS_DETACHED;

Local<String> win_hide = env()->windows_hide_string();

if (js_options->Get(win_hide)->BooleanValue())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with docs

@bzoz
Copy link
Contributor

bzoz commented Sep 13, 2017

It looks like the original issue is Unitech/pm2#2182 - console window pops-out when starting Node.js through PM2. Based on #7653 I added windowsHide: true to the spawn call that is used there.

This PR does not fix that issue, the console window still pops up with pm2 start something.js.

/cc @atrauzzi @vmarchaud

@vmarchaud
Copy link
Contributor

@bzoz From what i remember while working on this issue (one year ago already), the "fork mode" using spawn wasn't popping up console windows.
However the cluster mode was the problem, i believe that the problem came from the fact that the cluster mode is using the fork method, is this possible to pass windowsHide to the cluster implementation ?
Sadly i cant help much since i gave up my windows workstation also one year ago :(

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 13, 2017

@bzoz is there any value in me keeping this open then?

@bzoz
Copy link
Contributor

bzoz commented Sep 14, 2017

@vmarchaud hm, I observed the window popping out for a split-second when using pm2 start script.js. I think that uses the fork method. Now I'm confused and I don't know if I tested the right thing.

@cjihrig I think we should keep this open. At least until we verify what is the exact issue here.

@BridgeAR BridgeAR added blocked PRs that are blocked by other issues or PRs. wip Issues and PRs that are still a work in progress. labels Sep 19, 2017
@BridgeAR
Copy link
Member

@bzoz would you be so kind look into this issue further and assign this to yourself? It seems like you know what you have to look for and keeping a issue open to maybe look into something later on is not the best way to handle it ;-)

@bzoz
Copy link
Contributor

bzoz commented Sep 22, 2017

There is discussion going on in #15217 about this

@BridgeAR
Copy link
Member

@bzoz thanks for pointing this out.

@sam-github
Copy link
Contributor

I completely failed to figure out the specific conditions under which console windows pop up, much less that this flag prevents it, when I tried (see #2908 (comment)), but people do report this issue, its annoying, and would be great to have a fix for.

cjihrig added a commit to cjihrig/libuv that referenced this pull request Sep 26, 2017
The existing UV_PROCESS_WINDOWS_HIDE flag only applies to
executables linked to the WINDOWS subsystem. This allows
CONSOLE subsystem applications to pop up a console
window. This commit sets the CREATE_NO_WINDOW process
flag when UV_PROCESS_WINDOWS_HIDE to prevent this behavior.

Refs: nodejs/node#15380
Refs: joyent/libuv#627
Refs: libuv#965
PR-URL: libuv#1558
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 26, 2017

This should be fixed by the next libuv update.

@refack
Copy link
Contributor

refack commented Sep 26, 2017

As @bzoz writes in #15217 (comment)
{ detached: true } can cause a new console window to pop (but AFAICT it's a speed thing, so on my old machine it's 100% reproducible with the current code is master and with #15217)

const assert = require('assert');
const cp = require('child_process');

{
  const bat = cp.spawn('cmd.exe', ['/k', 'test.cmd'], { stdio: 'ignore', detached: true, windowsHide: true });

  bat.on('exit', (code) => {
    console.log(`Child exited with code ${code}`);
  });
}

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 26, 2017

@refack it seems like there are two problems:

  1. Hiding windows when the detached flag is not used. I think this should be fixed in libuv/libuv@b21c1f9.
  2. Hiding windows when detached is true. Is there a straightforward way to fix this? If not, we may have to just document it.

@refack
Copy link
Contributor

refack commented Sep 26, 2017

@cjihrig

  1. 🤞
  2. Might be covered by libuv/libuv@b21c1f9 as well (at least that's what the docs hint to), I'm building and testing now.

@tniessen
Copy link
Member

I would prefer to prefix Windows-specific options with win32 instead of windows.

@sam-github
Copy link
Contributor

Fwiw, I'm OK with just hide as the option name, or even hideWindow.

@refack
Copy link
Contributor

refack commented Sep 27, 2017

I would prefer to prefix Windows-specific options with win32 instead of windows.

Fwiw, I'm OK with just hide as the option name, or even hideWindow.

If this will forever be a WIN32 only flag, we already have windowsVerbatimArguments as legacy, so IMHO better to keep that "convention".
If there might be use for this on other platforms I'd go with hidden

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 27, 2017

I agree with @refack. In fact, I picked the name windowsHide because of windowsVerbatimArguments.

@cjihrig cjihrig mentioned this pull request Oct 3, 2017
2 tasks
cjihrig added a commit to cjihrig/node that referenced this pull request Oct 5, 2017
Refs: nodejs#15380
Refs: nodejs#15683
Fixes: nodejs#15394
Fixes: nodejs#15770
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@cjihrig
Copy link
Contributor Author

cjihrig commented Oct 24, 2017

Backport in #16425. The issue was that a change to the internals of spawnSync() had not been backported.

cjihrig added a commit to cjihrig/node that referenced this pull request Oct 24, 2017
Refs: nodejs#15380
PR-URL: nodejs#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
cjihrig added a commit to cjihrig/node that referenced this pull request Oct 24, 2017
Refs: nodejs#15380
PR-URL: nodejs#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
cjihrig added a commit to cjihrig/node that referenced this pull request Oct 24, 2017
In spawn_sync.cc, two consecutive loops are used to convert
data to strings, and compute the size of the data. This commit
merges the two independent loops into one.

Refs: nodejs#15380
PR-URL: nodejs#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 24, 2017
This commit exposes the UV_PROCESS_WINDOWS_HIDE flag in Node
as a windowsHide option to the child_process methods. The
option is only applicable to Windows, and is ignored elsewhere.

Backport-PR-URL: #16425
Fixes: #15217
PR-URL: #15380
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 24, 2017
Backport-PR-URL: #16426
Refs: #15380
PR-URL: #16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 24, 2017
Backport-PR-URL: #16426
Refs: #15380
PR-URL: #16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 24, 2017
In spawn_sync.cc, two consecutive loops are used to convert
data to strings, and compute the size of the data. This commit
merges the two independent loops into one.

Backport-PR-URL: #16426
Refs: #15380
PR-URL: #16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 25, 2017
PR-URL: #15745
Refs: #15380
Refs: #15683
Fixes: #15394
Fixes: #15770
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
Refs: nodejs/node#15380
PR-URL: nodejs/node#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
Refs: nodejs/node#15380
PR-URL: nodejs/node#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
In spawn_sync.cc, two consecutive loops are used to convert
data to strings, and compute the size of the data. This commit
merges the two independent loops into one.

Refs: nodejs/node#15380
PR-URL: nodejs/node#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

@bnoordhuis
Copy link
Member

In light of libuv/libuv#1625, currently not well-understood, it's probably better to hold off a little longer. I'll add labels.

@bnoordhuis
Copy link
Member

Hm, hadn't noticed this has already been merged into v8.x. If no bugs have been reported, then I guess there is no reason to keep it out of v6.x.

@vmarchaud
Copy link
Contributor

vmarchaud commented Nov 17, 2017

In the case of PM2, we added the windowsHide options to our fork an spawn calls and will soon publish it under the version 2.8.0. If there is any problem we should have people coming back to us about it, i will ping the libuv/libuv#1625 and here if that happen

addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
Refs: nodejs/node#15380
PR-URL: nodejs/node#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
Refs: nodejs/node#15380
PR-URL: nodejs/node#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
In spawn_sync.cc, two consecutive loops are used to convert
data to strings, and compute the size of the data. This commit
merges the two independent loops into one.

Refs: nodejs/node#15380
PR-URL: nodejs/node#16247
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell jasnell removed wip Issues and PRs that are still a work in progress. blocked PRs that are blocked by other issues or PRs. labels Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. child_process Issues and PRs related to the child_process subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.