forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is possible to cause a resource leak in SharedHandle if a worker is added after all other workers have been removed. This commit fixes the leak. Fixes: nodejs#2510
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test/parallel/test-cluster-shared-worker-added-after-disconnect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
const cluster = require('cluster'); | ||
cluster.schedulingPolicy = cluster.SCHED_NONE; | ||
|
||
if (cluster.isMaster) { | ||
var shotOnce = false; | ||
|
||
function shoot() { | ||
var c = net.connect(common.PORT, function() { | ||
c.unref(); | ||
|
||
Object.keys(cluster.workers).forEach(function(id) { | ||
cluster.workers[id].send('die'); | ||
}); | ||
}); | ||
} | ||
|
||
function fork() { | ||
var worker = cluster.fork(); | ||
worker.on('message', function() { | ||
if (!shotOnce) { | ||
shotOnce = true; | ||
shoot(); | ||
} | ||
fork(); | ||
}); | ||
} | ||
fork(); | ||
return; | ||
} | ||
|
||
var server = net.createServer({}, function(c) { | ||
c.end(); | ||
}); | ||
|
||
server.listen(common.PORT, function() { | ||
process.send('listening'); | ||
}); | ||
|
||
process.on('message', function listener(msg) { | ||
if (msg === 'die') { | ||
server.close(function() { | ||
process.exit(); | ||
}); | ||
} | ||
}); | ||
|