Ref: #1100
Ref: nodejs/node-v0.x-archive#16805
The following code will throw on OS X. It might take a while but it will happen. I usually see the error before runcount hits 2000.
'use strict';constfork=require('child_process').fork;constnet=require('net');constcount=12;constport=12346;if(process.argv[2]==='child'){letsockets=[];process.on('message',function(m,socket){functionsendClosed(id){process.send({id: id,status: 'closed'});};if(m.cmd==='new'){sockets.push(socket);}if(m.cmd==='close'){if(sockets[m.id].destroyed){thrownewError('socket already destroyed');}sockets[m.id].once('close',sendClosed.bind(null,m.id));sockets[m.id].destroy();}if(m.cmd==='clear'){sockets=[];}});}else{constchild=fork(process.argv[1],['child']);constserver=net.createServer();letsockets=[];server.on('connection',function(socket){child.send({cmd: 'new'},socket);sockets.push(socket);if(sockets.length===count){closeSockets(0);}});functioncreateSockets(){letj=count,client;while(j--){client=net.connect(port,'127.0.0.1');}}server.on('listening',function(){createSockets();});letrunCount=0;functioncloseSockets(i){if(i===count){console.log('run count: '+++runCount);child.send({cmd: 'clear'});sockets=[];returncreateSockets();}child.once('message',function(m){server.getConnections(function(err,num){closeSockets(i+1);});});child.send({id: i,cmd: 'close'});};server.listen(port,'127.0.0.1');}
Ref: #1100
Ref: nodejs/node-v0.x-archive#16805
The following code will throw on OS X. It might take a while but it will happen. I usually see the error before runcount hits 2000.