mirror of https://github.com/status-im/metro.git
Log server state when client is unexpetedly closed
Reviewed By: @javache Differential Revision: D2473036
This commit is contained in:
parent
ae3bf52f02
commit
3f61a4f846
|
@ -31,6 +31,10 @@ class SocketClient {
|
|||
this._ready = new Promise((resolve, reject) => {
|
||||
this._sock.on('connect', () => {
|
||||
this._sock.removeAllListeners('error');
|
||||
process.on('uncaughtException', (error) => {
|
||||
debug('uncaught error', error.stack);
|
||||
setImmediate(() => process.exit(1));
|
||||
});
|
||||
resolve(this);
|
||||
});
|
||||
this._sock.on('error', (e) => {
|
||||
|
@ -49,13 +53,24 @@ class SocketClient {
|
|||
|
||||
this._sock.on('close', () => {
|
||||
if (!this._closing) {
|
||||
const sockPathExists = fs.existsSync(sockPath);
|
||||
throw new Error(
|
||||
'Server closed unexpectedly.\n' +
|
||||
'Socket path: `' + sockPath + '` ' +
|
||||
(sockPathExists ? ' exists.' : 'doesn\'t exist') + '\n' +
|
||||
getServerLogs()
|
||||
);
|
||||
const terminate = (result) => {
|
||||
const sockPathExists = fs.existsSync(sockPath);
|
||||
throw new Error(
|
||||
'Server closed unexpectedly.\n' +
|
||||
'Server ping connection attempt result: ' + result + '\n' +
|
||||
'Socket path: `' + sockPath + '` ' +
|
||||
(sockPathExists ? ' exists.' : 'doesn\'t exist') + '\n' +
|
||||
getServerLogs()
|
||||
);
|
||||
};
|
||||
|
||||
// before throwing ping the server to see if it's still alive
|
||||
const socket = net.connect(sockPath);
|
||||
socket.on('connect', () => {
|
||||
socket.end();
|
||||
terminate('OK');
|
||||
});
|
||||
socket.on('error', error => terminate(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue