cluster: worker.disconnect() goes into forever loop though worker.isConnected() === true
System info:
$ uname -a
Darwin localhost 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64verified for node@5 and node@6.
code:
'use strict'; const http = require('http'), cluster = require('cluster'); if (cluster.isMaster) { http.createServer().listen(3000); cluster.fork(); } else { process.on('uncaughtException', e => { console.log('uncaught', e); if (cluster.worker.isConnected() && !cluster.worker.isDead()) { cluster.worker.disconnect(); } }); http.createServer().listen(3000); }
output:
$ node test
uncaught { Error: bind EADDRINUSE null:3000
at Object.exports._errnoException (util.js:896:11)
at exports._exceptionWithHostPort (util.js:919:20)
at cb (net.js:1311:16)
at rr (cluster.js:620:14)
at Worker.<anonymous> (cluster.js:590:9)
at process.<anonymous> (cluster.js:750:8)
at emitTwo (events.js:111:20)
at process.emit (events.js:191:7)
at handleMessage (internal/child_process.js:718:10)
at Pipe.channel.onread (internal/child_process.js:444:11)
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'bind',
address: null,
port: 3000 }
uncaught TypeError: Cannot read property 'apply' of undefined
at process.<anonymous> (cluster.js:750:7)
at emitTwo (events.js:111:20)
at process.emit (events.js:191:7)
at handleMessage (internal/child_process.js:718:10)
at Pipe.channel.onread (internal/child_process.js:444:11)
uncaught TypeError: Cannot read property 'apply' of undefined
at process.<anonymous> (cluster.js:750:7)
at emitTwo (events.js:111:20)
at process.emit (events.js:191:7)
at handleMessage (internal/child_process.js:718:10)
at Pipe.channel.onread (internal/child_process.js:444:11)
and it keeps going forever.
My expectations in this case:
- given worker says it's connected,
worker.disconnect()should be safe.
Or maybe I'm just doing smth wrong here.