Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

child_process.fork: don't modify args #1888

Closed
wants to merge 1 commit into from

3 participants

@koichik

Because child_process.fork() modify args argument, the worker processes after the second cannot get right arguments with cluster.
example:

a.js

console.log(process.env.NODE_WORKER_ID, process.argv);

result:

$ node cluster a.js foo bar
Detected 2 cpus
Worker 5097 online
Worker 5098 online
1 [ '/home/koichik/git/joyent/node/out/Release/node',
  '/tmp/a.js',
  'foo',
  'bar' ]
2 [ '/home/koichik/git/joyent/node/out/Release/node',
  '/tmp/a.js',
  '/tmp/a.js',
  'foo',
  'bar' ]
@bnoordhuis

Good one. Patch LGTM.

@koichik

Thanks!

@koichik koichik closed this in a09b747
@ry
ry commented

Thanks koichik

@koichik

@ry - My pleasure. BTW, do you have a plan to merge v0.4 branch to the master?

@ry
ry commented

Yeah I will merge next week

@koichik

Okay, thanks.

@japj japj referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@japj japj referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 14, 2011
  1. @koichik
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +1 −1  lib/child_process.js
  2. +3 −1 test/simple/test-child-process-fork.js
View
2  lib/child_process.js
@@ -124,7 +124,7 @@ function nop() { }
exports.fork = function(modulePath, args, options) {
if (!options) options = {};
- if (!args) args = [];
+ args = args ? args.slice(0) : [];
args.unshift(modulePath);
if (options.stdinStream) {
View
4 test/simple/test-child-process-fork.js
@@ -1,8 +1,10 @@
var assert = require('assert');
var common = require('../common');
var fork = require('child_process').fork;
+var args = ['foo', 'bar'];
-var n = fork(common.fixturesDir + '/child-process-spawn-node.js');
+var n = fork(common.fixturesDir + '/child-process-spawn-node.js', args);
+assert.deepEqual(args, ['foo', 'bar']);
var messageCount = 0;
Something went wrong with that request. Please try again.