镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

child_process.fork not passing along options.env #20749

Description

@borisovg
  • Version: v8.11.1
  • Platform: Linux
  • Subsystem: Child Process

parent.js:

require('child_process').fork('./child.js', undefined, { env: { FOO: 'bar' } });

child.js

console.log(process.env.FOO);

output:

$ FOO=foo node parent.js 
foo

Activity

  1. vsemozhetbyt commented on May 15, 2018

    @vsemozhetbyt
    Contributor

    Try:

    require('child_process').fork('./child.js', [], { env: { FOO: 'bar' } });

    @nodejs/child_process Is this expected behavior that the second argument set in undefined or null prevents the third one from being transferred?

  2. borisovg commented on May 15, 2018

    @borisovg
    Author

    @vsemozhetbyt thanks - this also works:

    require('child_process').fork('./child.js', { env: { FOO: 'bar' } });
    

    I can guess why this is happening, having seen enough dodgy JS code that does parameter overloading ;)

  3. shobhitchittora commented on May 21, 2018

    @shobhitchittora
    Contributor

    @vsemozhetbyt I think the check for arguments can be improved.

    if (pos < arguments.length && arguments[pos] != null) {

    if (typeof arguments[pos] !== 'object') {

    We can check for emptiness (something like lodash.isEmpty) for both of the arguments. Then we can conditionally check whether both are present or not.

    Or we can just document the behavior altogether. 😛

  4. ryzokuken commented on May 21, 2018

    @ryzokuken
    Contributor

    This looks like an ambiguity problem, and improving docs seems to be the logical way forward to me as well.

  5. borisovg commented on May 21, 2018

    @borisovg
    Author

    As a developer, even if documented, this looks like broken behaviour. Throwing an error on an invalid argument type is perfectly acceptable, but ignoring the subsequent argument is just shoddy - to be tolerated in a third party lib but not a core Node module. Just my opinion.

  6. ryzokuken commented on May 21, 2018

    @ryzokuken
    Contributor

    @borisovg if you insist, I could look a tad deeper into this over the course of the next few days and hack up a small PR.

  7. 2 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions