You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
child_process: fork does not accept null or undefined args array #10819
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.
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?
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.
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.
Activity
Fishrock123 commentedon Jan 16, 2017
I think it would make more sense to throw a TypeError over seeing it as no-args? What does everyone else think?
sam-github commentedon Jan 16, 2017
The handling should be the same across the
child_processAPIs for when argv arrays are passednullorundefined. What doexecFile/spawn[Sync]()do in this case?trendsetter37 commentedon Jan 16, 2017
@sam-github spawn and execFile uses a normalizeSpawnArguments function to parse arguments.
where as fork does something different...or it's own thing entirely rather.
sam-github commentedon Jan 16, 2017
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.
Trott commentedon Jul 16, 2017
@sam-github Should this remain open?
sam-github commentedon Jul 21, 2017
Yes, it sounds like there is an inconsistency, but no one has looked into it yet.
gireeshpunathil commentedon May 14, 2018
this is addressed through #10866 and is a close candidate? I may be wrong.
laykun commentedon May 29, 2018
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.
gireeshpunathil commentedon May 29, 2018
#20882 is a work in progress to address the ambiguity. Feel free to review that PR and provide any inputs, thanks!
juanarbol commentedon Apr 26, 2020
This was fixed on #22416
Closing this issue, thanks for the report!