-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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. This commit fixes the leak. Fixes: #2510 PR-URL: #5152 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
52 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
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,48 @@ | ||
// On some platforms this test triggers an assertion in cluster.js. | ||
// The assertion protects against memory leaks. | ||
// https://github.com/nodejs/node/pull/3510 | ||
|
||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var net = require('net'); | ||
var cluster = require('cluster'); | ||
cluster.schedulingPolicy = cluster.SCHED_NONE; | ||
|
||
if (cluster.isMaster) { | ||
var conn, worker1, worker2; | ||
|
||
worker1 = cluster.fork(); | ||
worker1.on('message', common.mustCall(function() { | ||
worker2 = cluster.fork(); | ||
worker2.on('online', function() { | ||
conn = net.connect(common.PORT, common.mustCall(function() { | ||
worker1.disconnect(); | ||
worker2.disconnect(); | ||
})); | ||
conn.on('error', function(e) { | ||
// ECONNRESET is OK | ||
if (e.code !== 'ECONNRESET') | ||
throw e; | ||
}); | ||
}); | ||
})); | ||
|
||
cluster.on('exit', function(worker, exitCode, signalCode) { | ||
assert(worker === worker1 || worker === worker2); | ||
assert.strictEqual(exitCode, 0); | ||
assert.strictEqual(signalCode, null); | ||
if (Object.keys(cluster.workers).length === 0) | ||
conn.destroy(); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
var server = net.createServer(function(c) { | ||
c.end('bye'); | ||
}); | ||
|
||
server.listen(common.PORT, function() { | ||
process.send('listening'); | ||
}); |