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'; 6const common = require('../common'); 7const assert = require('assert'); 8const net = require('net'); 9const cluster = require('cluster'); 10cluster.schedulingPolicy = cluster.SCHED_NONE; 11 12if (cluster.isMaster) { 13 let conn, worker2; 14 15 const worker1 = cluster.fork(); 16 worker1.on('listening', common.mustCall(function(address) { 17 worker2 = cluster.fork(); 18 worker2.on('online', function() { 19 conn = net.connect(address.port, common.mustCall(function() { 20 worker1.disconnect(); 21 worker2.disconnect(); 22 })); 23 conn.on('error', function(e) { 24 // ECONNRESET is OK 25 if (e.code !== 'ECONNRESET') 26 throw e; 27 }); 28 }); 29 })); 30 31 cluster.on('exit', function(worker, exitCode, signalCode) { 32 assert(worker === worker1 || worker === worker2); 33 assert.strictEqual(exitCode, 0); 34 assert.strictEqual(signalCode, null); 35 if (Object.keys(cluster.workers).length === 0) 36 conn.destroy(); 37 }); 38 39 return; 40} 41 42const server = net.createServer(function(c) { 43 c.on('error', function(e) { 44 // ECONNRESET is OK, so we don't exit with code !== 0 45 if (e.code !== 'ECONNRESET') 46 throw e; 47 }); 48 c.end('bye'); 49}); 50 51server.listen(0); 52