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._ready = new Promise((resolve, reject) => {
|
||||||
this._sock.on('connect', () => {
|
this._sock.on('connect', () => {
|
||||||
this._sock.removeAllListeners('error');
|
this._sock.removeAllListeners('error');
|
||||||
|
process.on('uncaughtException', (error) => {
|
||||||
|
debug('uncaught error', error.stack);
|
||||||
|
setImmediate(() => process.exit(1));
|
||||||
|
});
|
||||||
resolve(this);
|
resolve(this);
|
||||||
});
|
});
|
||||||
this._sock.on('error', (e) => {
|
this._sock.on('error', (e) => {
|
||||||
|
@ -49,13 +53,24 @@ class SocketClient {
|
||||||
|
|
||||||
this._sock.on('close', () => {
|
this._sock.on('close', () => {
|
||||||
if (!this._closing) {
|
if (!this._closing) {
|
||||||
|
const terminate = (result) => {
|
||||||
const sockPathExists = fs.existsSync(sockPath);
|
const sockPathExists = fs.existsSync(sockPath);
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Server closed unexpectedly.\n' +
|
'Server closed unexpectedly.\n' +
|
||||||
|
'Server ping connection attempt result: ' + result + '\n' +
|
||||||
'Socket path: `' + sockPath + '` ' +
|
'Socket path: `' + sockPath + '` ' +
|
||||||
(sockPathExists ? ' exists.' : 'doesn\'t exist') + '\n' +
|
(sockPathExists ? ' exists.' : 'doesn\'t exist') + '\n' +
|
||||||
getServerLogs()
|
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