Remove server error listener so that it throws

Summary: @​public
We swallow errors like it's nobody's business :(
Having an error handler that `reject`s after the promise has been resolved is a no-op. In node, if there is no `error` event handler then the error would throw.

So after we start listening and we want to resolve the promise, we remove the error listener so that we make sure errors actually throw.

Finally, I made the `uncaughtError` handler log `error.stack` so we can get an idea of what's going on.

Reviewed By: @martinbigio

Differential Revision: D2468472
This commit is contained in:
Amjad Masad 2015-09-22 15:45:03 -07:00 коммит произвёл facebook-github-bot-7
Родитель 30cca276fa
Коммит 45ed000d4b
1 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -23,8 +23,15 @@ class SocketServer {
this._server = net.createServer();
this._server.listen(sockPath);
this._ready = new Promise((resolve, reject) => {
this._server.on('error', (e) => reject(e));
this._server.on('listening', () => {
this._server.once('error', (e) => reject(e));
this._server.once('listening', () => {
// Remove error listener so we make sure errors propagate.
this._server.removeAllListeners('error');
this._server.on(
'close',
() => debug('server closed')
);
debug(
'Process %d listening on socket path %s ' +
'for server with options %j',
@ -41,7 +48,7 @@ class SocketServer {
});
process.on('uncaughtException', (error) => {
debug('uncaught error', error);
debug('uncaught error', error.stack);
setImmediate(() => process.exit(1));
});