mirror of https://github.com/status-im/metro.git
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:
parent
0671b2b6f2
commit
0e8f6e4ed3
|
@ -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));
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue