mirror of https://github.com/status-im/metro.git
[react-packager] Allow a longer startup time before the server dies
Summary: 1. When the server starts up, it only gives itself 30 second to live before receiving any connections/jobs 2. There is a startup cost with starting the server and handshaking 3. The server dies before the client has a chance to connect to it Solution: 1. While the server should die pretty fast after it's done it's work, we should have a longer timeout for starting it 2. I also added accompanying server logs with client connection errors
This commit is contained in:
parent
4b14a2f783
commit
2727f4b5ea
|
@ -12,6 +12,7 @@ const Bundle = require('../Bundler/Bundle');
|
||||||
const Promise = require('promise');
|
const Promise = require('promise');
|
||||||
const bser = require('bser');
|
const bser = require('bser');
|
||||||
const debug = require('debug')('ReactPackager:SocketClient');
|
const debug = require('debug')('ReactPackager:SocketClient');
|
||||||
|
const fs = require('fs');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const tmpdir = require('os').tmpdir();
|
const tmpdir = require('os').tmpdir();
|
||||||
|
@ -32,6 +33,11 @@ class SocketClient {
|
||||||
this._sock.on('error', (e) => {
|
this._sock.on('error', (e) => {
|
||||||
e.message = `Error connecting to server on ${sockPath} ` +
|
e.message = `Error connecting to server on ${sockPath} ` +
|
||||||
`with error: ${e.message}`;
|
`with error: ${e.message}`;
|
||||||
|
|
||||||
|
if (fs.existsSync(LOG_PATH)) {
|
||||||
|
e.message += '\nServer logs:\n' + fs.readFileSync(LOG_PATH, 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,7 @@ const fs = require('fs');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
const MAX_IDLE_TIME = 30 * 1000;
|
const MAX_IDLE_TIME = 30 * 1000;
|
||||||
|
const MAX_STARTUP_TIME = 5 * 60 * 1000;
|
||||||
|
|
||||||
class SocketServer {
|
class SocketServer {
|
||||||
constructor(sockPath, options) {
|
constructor(sockPath, options) {
|
||||||
|
@ -43,7 +44,7 @@ class SocketServer {
|
||||||
options.nonPersistent = true;
|
options.nonPersistent = true;
|
||||||
this._packagerServer = new Server(options);
|
this._packagerServer = new Server(options);
|
||||||
this._jobs = 0;
|
this._jobs = 0;
|
||||||
this._dieEventually();
|
this._dieEventually(MAX_STARTUP_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
onReady() {
|
onReady() {
|
||||||
|
@ -118,7 +119,7 @@ class SocketServer {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
_dieEventually() {
|
_dieEventually(delay = MAX_IDLE_TIME) {
|
||||||
clearTimeout(this._deathTimer);
|
clearTimeout(this._deathTimer);
|
||||||
this._deathTimer = setTimeout(() => {
|
this._deathTimer = setTimeout(() => {
|
||||||
if (this._jobs <= 0 && this._numConnections <= 0) {
|
if (this._jobs <= 0 && this._numConnections <= 0) {
|
||||||
|
@ -126,7 +127,7 @@ class SocketServer {
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
this._dieEventually();
|
this._dieEventually();
|
||||||
}, MAX_IDLE_TIME);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
static listenOnServerIPCMessages() {
|
static listenOnServerIPCMessages() {
|
||||||
|
|
Loading…
Reference in New Issue