From 0e8f6e4ed3dce3fc495ac35c27d4da663825e6f7 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Tue, 22 Sep 2015 15:45:03 -0700 Subject: [PATCH] Remove server error listener so that it throws MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- react-packager/src/SocketInterface/SocketServer.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/react-packager/src/SocketInterface/SocketServer.js b/react-packager/src/SocketInterface/SocketServer.js index e9b6c2be..3d8e3a33 100644 --- a/react-packager/src/SocketInterface/SocketServer.js +++ b/react-packager/src/SocketInterface/SocketServer.js @@ -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)); });