Skip to content

child_process: fork does not accept null or undefined args array #10819

Description

@trendsetter37
  • Version: 8.0.0-pre

  • Platform: Linux jsully 4.8.0-040800-generic #201610022031 SMP Mon Oct 3 00:32:57 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

  • Subsystem: child_process

It appears as though fork assumes there are no options args when the arg array is null or undefined. This results in ignored parameters set in the options object.

More info here

I will update with further details once I dig into the code.

ref. #10793

Activity

  1. Fishrock123 commented on Jan 16, 2017

    @Fishrock123
    Contributor

    I think it would make more sense to throw a TypeError over seeing it as no-args? What does everyone else think?

  2. sam-github commented on Jan 16, 2017

    @sam-github
    Contributor

    The handling should be the same across the child_process APIs for when argv arrays are passed null or undefined. What do execFile/spawn[Sync]() do in this case?

  3. trendsetter37 commented on Jan 16, 2017

    @trendsetter37
    ContributorAuthor

    @sam-github spawn and execFile uses a normalizeSpawnArguments function to parse arguments.

    var spawn = exports.spawn = function(/*file, args, options*/) {
      var opts = normalizeSpawnArguments.apply(null, arguments);
      var options = opts.options;
      var child = new ChildProcess();
    
      debug('spawn', opts.args, options);
    
      child.spawn({
        file: opts.file,
        args: opts.args,
        cwd: options.cwd,
        windowsVerbatimArguments: !!options.windowsVerbatimArguments,
        detached: !!options.detached,
        envPairs: opts.envPairs,
        stdio: options.stdio,
        uid: options.uid,
        gid: options.gid
      });

    where as fork does something different...or it's own thing entirely rather.

  4. sam-github commented on Jan 16, 2017

    @sam-github
    Contributor

    How those functions are implemented internally is their own business, how they behave should be consistent. spawn and exec didn't used to share implementation, and their behaviour was bafflingly inconsistent, the code sharing helps ensure they behave identically, as do the tests.

  5. Trott commented on Jul 16, 2017

    @Trott
    Member

    @sam-github Should this remain open?

  6. sam-github commented on Jul 21, 2017

    @sam-github
    Contributor

    Yes, it sounds like there is an inconsistency, but no one has looked into it yet.

  7. gireeshpunathil commented on May 14, 2018

    @gireeshpunathil
    Member

    this is addressed through #10866 and is a close candidate? I may be wrong.

  8. laykun commented on May 29, 2018

    @laykun

    I wasted a whole bunch of time figuring out why my child processes were crashing due to invalid debug options even when I was passing in a new inspect port to use. Turns on I was using null as my args argument assuming it would NOT ignore the third argument in the fork function. This is very odd behaviour and will cost more time. The function should process arguments on a case by case basis and not be dependent on prior arguments. Seeing as this behaviour is not mentioned in the documentation and using null / undefined as an argument should be perfectly acceptable then this behaviour needs to change.

  9. gireeshpunathil commented on May 29, 2018

    @gireeshpunathil
    Member

    #20882 is a work in progress to address the ambiguity. Feel free to review that PR and provide any inputs, thanks!

  10. juanarbol commented on Apr 26, 2020

    @juanarbol
    Member

    This was fixed on #22416

    Closing this issue, thanks for the report!

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