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

test: implement setproctitle for windows #14042

Closed
wants to merge 2 commits into from

Conversation

refack
Copy link
Contributor

@refack refack commented Jul 2, 2017

Fixes: #14039

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

test,process,windows

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Jul 2, 2017
@refack refack added process Issues and PRs related to the process subsystem. windows Issues and PRs related to the Windows platform. labels Jul 2, 2017
// The title shouldn't be too long; libuv's uv_set_process_title() out of
// security considerations no longer overwrites envp, only argv, so the
// maximum title length is possibly quite short.
let title = String(process.pid);
const title = String(Date.now()).substr(-4, 4);
Copy link
Member

@addaleax addaleax Jul 2, 2017

Choose a reason for hiding this comment

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

Why this change? (to clarify: I’m sure there’s a reason, I just don’t see it?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was checking what is actually the limit, and it turns out to be 4 chars, and it fails on my machine (when pid > 10000), so I picked a fairly random seed, and truncated to 4.

Copy link
Member

Choose a reason for hiding this comment

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

Can you use a constant value then? I know this wasn’t the case before, but it’s not really a good idea to use random values in tests, where reproducibility matters (alternative: print the title to stderr, that should work as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhh. that's a good idea!
...
But it only give us node's "internal" view, while ps gives us how the external system sees the title
...
The issue with a constant value is that zombies will give us a false positive. We need a secret that only know to the testing process

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right. Yeah, in that case, print it out to stderr.

@refack
Copy link
Contributor Author

refack commented Jul 2, 2017

I could add some more comments, this is fairly black magic stuff...

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jul 2, 2017

FWIW, the reason to be careful with constants (or something that can be equal by a chance in different runs) here: #12792

@refack
Copy link
Contributor Author

refack commented Jul 2, 2017

I'm totally not in love with the new code, if anybody has any idea how to improve it, please 🙏
/cc @nodejs/platform-windows @nodejs/testing @richardlau

const cmd = (() => {
if (common.isWindows) {
// For windows we need to spawn a new `window` so it will get the title.
// For that we need a `shell`, and to use `start`
Copy link
Member

Choose a reason for hiding this comment

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

Could do with a short comment here stating that changing the title on Windows changes the title of the Window, which may not be the node process. This add s bit of context as to why the test is different on Windows.

@refack refack force-pushed the complete-test-setproctitle branch from 47bcd52 to d10d40d Compare July 3, 2017 17:41
);
const PSL = 'Powershell -NoProfile -ExecutionPolicy Unrestricted -Command';
const winTitle = '$_.mainWindowTitle';
return `${PSL} "ps | ? {${winTitle} -eq '${title}'} | % {${winTitle}}"`;
Copy link
Member

Choose a reason for hiding this comment

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

I think this is subject to race condition, where the PowerShell script may run before the spawned child process changes the title? Maybe we can use fork() instead of spawn() and use the IPC channel for sequencing? Would also have the benefit of not having to kill the child.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll research that, also I think there is a guarantee that something (not sure what) has to finish before spawn returns.
Also AFAIK it's possible to establish an IPC via spawn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

P.S. I have seen inconsistant results but I attributed them to the child exiting too soon 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Again, with IPC we could get the child to wait around instead of arbitrary timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't use IPC because the script is run not in the child but in a grandchild created with START...

Copy link
Member

Choose a reason for hiding this comment

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

Hm, is there any solution to this? Because without this solved it seems like there can not be any progress.

@BridgeAR
Copy link
Member

@refack this needs a rebase

@BridgeAR
Copy link
Member

@nodejs/testing PTAL

@refack refack self-assigned this Sep 23, 2017
@BridgeAR
Copy link
Member

@nodejs/platform-windows PTAL

@BridgeAR
Copy link
Member

Ping @nodejs/testing @nodejs/platform-windows again. PTAL

Copy link
Member

@richardlau richardlau left a comment

Choose a reason for hiding this comment

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

I'm still concerned that there's a race condition in the test that would introduce a new flake.

@BridgeAR
Copy link
Member

Closing due to no further progress. If someone thinks this should be reopened, please do so.

@BridgeAR BridgeAR closed this Dec 15, 2017
@refack refack removed their assignment Oct 12, 2018
@refack refack added the stalled Issues and PRs that are stalled. label Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. stalled Issues and PRs that are stalled. test Issues and PRs related to the tests. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: improve parallel/test-setproctitle.js
6 participants