| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -345,7 +345,10 @@ function masterInit() { | |||
| 345 | 345 | * if it has disconnected, otherwise we might | |
| 346 | 346 | * still want to access it. | |
| 347 | 347 | */ | |
| 348 | - if (!worker.isConnected()) removeWorker(worker); | ||
| 348 | + if (!worker.isConnected()) { | ||
| 349 | + removeHandlesForWorker(worker); | ||
| 350 | + removeWorker(worker); | ||
| 351 | + } | ||
| 349 | 352 | ||
| 350 | 353 | worker.suicide = !!worker.suicide; | |
| 351 | 354 | worker.state = 'dead'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,53 @@ | |||
| 1 | + // In Node 4.2.1 on operating systems other than Linux, this test triggers an | ||
| 2 | + // assertion in cluster.js. The assertion protects against memory leaks. | ||
| 3 | + // https://github.com/nodejs/node/pull/3510 | ||
| 4 | + | ||
| 5 | + 'use strict'; | ||
| 6 | + const common = require('../common'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const net = require('net'); | ||
| 9 | + const cluster = require('cluster'); | ||
| 10 | + cluster.schedulingPolicy = cluster.SCHED_NONE; | ||
| 11 | + | ||
| 12 | + if (cluster.isMaster) { | ||
| 13 | + var conn, worker1, worker2; | ||
| 14 | + | ||
| 15 | + worker1 = cluster.fork(); | ||
| 16 | + worker1.on('message', common.mustCall(function() { | ||
| 17 | + worker2 = cluster.fork(); | ||
| 18 | + conn = net.connect(common.PORT, common.mustCall(function() { | ||
| 19 | + worker1.send('die'); | ||
| 20 | + worker2.send('die'); | ||
| 21 | + })); | ||
| 22 | + conn.on('error', function(e) { | ||
| 23 | + // ECONNRESET is OK | ||
| 24 | + if (e.code !== 'ECONNRESET') | ||
| 25 | + throw e; | ||
| 26 | + }); | ||
| 27 | + })); | ||
| 28 | + | ||
| 29 | + cluster.on('exit', function(worker, exitCode, signalCode) { | ||
| 30 | + assert(worker === worker1 || worker === worker2); | ||
| 31 | + assert.strictEqual(exitCode, 0); | ||
| 32 | + assert.strictEqual(signalCode, null); | ||
| 33 | + if (Object.keys(cluster.workers).length === 0) | ||
| 34 | + conn.destroy(); | ||
| 35 | + }); | ||
| 36 | + | ||
| 37 | + return; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + var server = net.createServer(function(c) { | ||
| 41 | + c.end('bye'); | ||
| 42 | + }); | ||
| 43 | + | ||
| 44 | + server.listen(common.PORT, function() { | ||
| 45 | + process.send('listening'); | ||
| 46 | + }); | ||
| 47 | + | ||
| 48 | + process.on('message', function(msg) { | ||
| 49 | + if (msg !== 'die') return; | ||
| 50 | + server.close(function() { | ||
| 51 | + setImmediate(() => process.disconnect()); | ||
| 52 | + }); | ||
| 53 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments