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

worker: add args constructor option #30559

Closed
wants to merge 1 commit into from

Conversation

@legendecas
Copy link
Member

legendecas commented Nov 20, 2019

A convenience option to populate process.argv in worker threads.

Fixes: #30531

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
@legendecas legendecas force-pushed the legendecas:issue-30531 branch from eac3bd6 to 5c8825d Nov 20, 2019
doc/api/worker_threads.md Outdated Show resolved Hide resolved
lib/internal/worker.js Outdated Show resolved Hide resolved
doc/api/worker_threads.md Outdated Show resolved Hide resolved
@legendecas legendecas force-pushed the legendecas:issue-30531 branch from 5c8825d to 145cad8 Nov 24, 2019
doc/api/worker_threads.md Outdated Show resolved Hide resolved
doc/api/worker_threads.md Outdated Show resolved Hide resolved
lib/internal/worker.js Outdated Show resolved Hide resolved
lib/internal/worker.js Outdated Show resolved Hide resolved
@legendecas legendecas force-pushed the legendecas:issue-30531 branch from cc43dfd to 94bd692 Nov 24, 2019
@nodejs-github-bot

This comment has been minimized.

@legendecas legendecas force-pushed the legendecas:issue-30531 branch from 94bd692 to bc9eb5c Nov 24, 2019
@legendecas

This comment has been minimized.

Copy link
Member Author

legendecas commented Nov 24, 2019

@addaleax @gireeshpunathil @lundibundi just found a new issue on eval mode of workers. PTAL again...😅

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

const assert = require('assert');
assert.deepStrictEqual(
process.argv,
[process.execPath, 'null', 'foo', '123', String(Symbol('bar'))]

This comment has been minimized.

Copy link
@addaleax

addaleax Nov 25, 2019

Member

I know this matches node --eval, but … this feels a bit wrong to me.

Shouldn’t the second entry always be the filename for the current script, even if it’s a fake one because of eval: true?

This comment has been minimized.

Copy link
@legendecas

legendecas Nov 25, 2019

Author Member

Would it make sense that the filename is [worker eval] for node -p '__filename' printing [eval]?

This comment has been minimized.

Copy link
@addaleax

addaleax Nov 26, 2019

Member

Yeah, I’m good with that personally 👍

This comment has been minimized.

Copy link
@legendecas

legendecas Nov 27, 2019

Author Member

It's more common to get filename from the __filename right? Since __filename in eval worker already presents and has a value of [worker eval], is it required to add the filename to argv while we don't generally have it in our node -e 'process.argv'?

This comment has been minimized.

Copy link
@addaleax

addaleax Nov 27, 2019

Member

It's more common to get filename from the __filename right?

__filename and process.argv[1] are different things; the former is the path of the current CJS module, the latter is the path of the main module.

Since __filename in eval worker already presents and has a value of [worker eval], is it required to add the filename to argv while we don't generally have it in our node -e 'process.argv'?

You can feel free to omit this, but I’d consider it inconsistent that process.argv doesn’t include a fake filename for node -e. It seems to break expectations for me, because in node -e the structure of process.argv should be the same as elsewhere.

Changing that for node -e is a breaking change – and I’d be willing to open a PR for that – but here we have the chance to be consistent from the beginning.

This comment has been minimized.

Copy link
@legendecas

legendecas Nov 28, 2019

Author Member

Tested against bash, in which argv never includes filename, in both eval mode or script mode. So it might make sense to add a fake filename in eval mode since we have it in script mode.

I'll update the PR to include the filename in eval worker's argv to keep consistency with script mode.

@addaleax addaleax removed the author ready label Nov 29, 2019
@legendecas legendecas force-pushed the legendecas:issue-30531 branch 3 times, most recently from eae77c1 to d2ce74f Nov 30, 2019
@nodejs-github-bot

This comment has been minimized.

A convenience option to populate `process.argv` in worker threads.
@legendecas legendecas force-pushed the legendecas:issue-30531 branch from d2ce74f to 9dde270 Dec 1, 2019
@legendecas

This comment has been minimized.

Copy link
Member Author

legendecas commented Dec 1, 2019

Tests failed for the case test/parallel/test-worker-process-argv.js was initially ran in workers. Trying to fix it by adding an additional check on if the worker was started by the expected options.

@nodejs-github-bot

This comment has been minimized.

const name = '[worker eval]';
// This is necessary for CJS module compilation.
// TODO: pass this with something really internal.
ObjectDefineProperty(process, '_eval', {

This comment has been minimized.

Copy link
@jasnell

jasnell Dec 1, 2019

Member

Would a symbol be better/possible here?

This comment has been minimized.

Copy link
@addaleax

addaleax Dec 1, 2019

Member

This is to match with what the CJS loader expects for the --eval CLI option, unfortunately

@addaleax

This comment has been minimized.

Copy link
Member

addaleax commented Dec 3, 2019

Landed in 3ebae6c 🎉

@addaleax addaleax closed this Dec 3, 2019
addaleax added a commit that referenced this pull request Dec 3, 2019
A convenience option to populate `process.argv` in worker threads.

PR-URL: #30559
Fixes: #30531
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
@legendecas legendecas deleted the legendecas:issue-30531 branch Dec 4, 2019
targos added a commit that referenced this pull request Dec 9, 2019
A convenience option to populate `process.argv` in worker threads.

PR-URL: #30559
Fixes: #30531
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Sebastien-Ahkrin added a commit to Sebastien-Ahkrin/node that referenced this pull request Dec 11, 2019
A convenience option to populate `process.argv` in worker threads.

PR-URL: nodejs#30559
Fixes: nodejs#30531
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Dec 13, 2019
MylesBorins added a commit that referenced this pull request Dec 16, 2019
This is a security release.

This release includes a single commit, an update to npm to 6.13.4.

For more details about the vulnerability please consult the npm blog:

https://blog.npmjs.org/post/189618601100/binary-planting-with-the-npm-cli

Notable Changes:
* deps:
  - update npm to 6.13.4
    #30904
  - update uvwasi (Anna Henningsen)
    #30745
  - upgrade to libuv 1.34.0 (Colin Ihrig)
    #30783
* doc:
  - docs deprecate http finished (Robert Nagy)
    #28679
* events:
  - add captureRejection option (Matteo Collina)
    #27867
* http:
  - add captureRejection support (Matteo Collina)
    #27867
  - llhttp opt-in insecure HTTP header parsing (Sam Roberts)
    #30567
* http2:
  - implement capture rection for 'request' and 'stream' events (Matteo Collina)
    #27867
* net:
  - implement capture rejections for 'connection' event (Matteo Collina)
    #27867
* repl:
  - support previews by eager evaluating input (Ruben Bridgewater)
    #30811
* stream:
  - add support for captureRejection option (Matteo Collina)
    #27867
* tls:
  - implement capture rejections for 'secureConnection' event (Matteo Collina)
    #27867
  - expose IETF name for current cipher suite (Sam Roberts)
    #30637
* worker:
  - add argv constructor option (legendecas)
    #30559

PR-URL: #30937
MylesBorins added a commit that referenced this pull request Dec 16, 2019
This is a security release.

This release includes a single commit, an update to npm to 6.13.4.

For more details about the vulnerability please consult the npm blog:

https://blog.npmjs.org/post/189618601100/binary-planting-with-the-npm-cli

Notable Changes:
* deps:
  * update npm to 6.13.4
    #30904
  * update uvwasi (Anna Henningsen)
    #30745
  * upgrade to libuv 1.34.0 (Colin Ihrig)
    #30783
* doc:
  * docs deprecate http finished (Robert Nagy)
    #28679
* events:
  * add captureRejection option (Matteo Collina)
    #27867
* http:
  * add captureRejection support (Matteo Collina)
    #27867
  * llhttp opt-in insecure HTTP header parsing (Sam Roberts)
    #30567
* http2:
  * implement capture rection for 'request' and 'stream' events (Matteo Collina)
    #27867
* net:
  * implement capture rejections for 'connection' event (Matteo Collina)
    #27867
* repl:
  * support previews by eager evaluating input (Ruben Bridgewater)
    #30811
* stream:
  * add support for captureRejection option (Matteo Collina)
    #27867
* tls:
  * implement capture rejections for 'secureConnection' event (Matteo Collina)
    #27867
  * expose IETF name for current cipher suite (Sam Roberts)
    #30637
* worker:
  * add argv constructor option (legendecas)
    #30559

PR-URL: #30937
MylesBorins added a commit that referenced this pull request Dec 16, 2019
This is a security release.

For more details about the vulnerability please consult the npm blog:

https://blog.npmjs.org/post/189618601100/binary-planting-with-the-npm-cli

Notable Changes:
* deps:
  * update npm to 6.13.4
    #30904
  * update uvwasi (Anna Henningsen)
    #30745
  * upgrade to libuv 1.34.0 (Colin Ihrig)
    #30783
* doc:
  * docs deprecate http finished (Robert Nagy)
    #28679
* events:
  * add captureRejection option (Matteo Collina)
    #27867
* http:
  * add captureRejection support (Matteo Collina)
    #27867
  * llhttp opt-in insecure HTTP header parsing (Sam Roberts)
    #30567
* http2:
  * implement capture rection for 'request' and 'stream' events (Matteo Collina)
    #27867
* net:
  * implement capture rejections for 'connection' event (Matteo Collina)
    #27867
* repl:
  * support previews by eager evaluating input (Ruben Bridgewater)
    #30811
* stream:
  * add support for captureRejection option (Matteo Collina)
    #27867
* tls:
  * implement capture rejections for 'secureConnection' event (Matteo Collina)
    #27867
  * expose IETF name for current cipher suite (Sam Roberts)
    #30637
* worker:
  * add argv constructor option (legendecas)
    #30559

PR-URL: #30937
MylesBorins added a commit that referenced this pull request Dec 17, 2019
This is a security release.

For more details about the vulnerability please consult the npm blog:

https://blog.npmjs.org/post/189618601100/binary-planting-with-the-npm-cli

Notable Changes:
* deps:
  * update npm to 6.13.4
    #30904
  * update uvwasi (Anna Henningsen)
    #30745
  * upgrade to libuv 1.34.0 (Colin Ihrig)
    #30783
* doc:
  * docs deprecate http finished (Robert Nagy)
    #28679
* events:
  * add captureRejection option (Matteo Collina)
    #27867
* http:
  * add captureRejection support (Matteo Collina)
    #27867
  * llhttp opt-in insecure HTTP header parsing (Sam Roberts)
    #30567
* http2:
  * implement capture rection for 'request' and 'stream' events (Matteo Collina)
    #27867
* net:
  * implement capture rejections for 'connection' event (Matteo Collina)
    #27867
* repl:
  * support previews by eager evaluating input (Ruben Bridgewater)
    #30811
* stream:
  * add support for captureRejection option (Matteo Collina)
    #27867
* tls:
  * implement capture rejections for 'secureConnection' event (Matteo Collina)
    #27867
  * expose IETF name for current cipher suite (Sam Roberts)
    #30637
* worker:
  * add argv constructor option (legendecas)
    #30559

PR-URL: #30937
targos added a commit that referenced this pull request Jan 14, 2020
A convenience option to populate `process.argv` in worker threads.

PR-URL: #30559
Fixes: #30531
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.