[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:
Amjad Masad 2015-09-07 10:44:02 -07:00
parent 59b9dc8829
commit bceab6c1c2
2 changed files with 11 additions and 4 deletions

View File

@ -12,6 +12,7 @@ const Bundle = require('../Bundler/Bundle');
const Promise = require('promise');
const bser = require('bser');
const debug = require('debug')('ReactPackager:SocketClient');
const fs = require('fs');
const net = require('net');
const path = require('path');
const tmpdir = require('os').tmpdir();
@ -30,8 +31,13 @@ class SocketClient {
this._ready = new Promise((resolve, reject) => {
this._sock.on('connect', () => resolve(this));
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}`;
if (fs.existsSync(LOG_PATH)) {
e.message += '\nServer logs:\n' + fs.readFileSync(LOG_PATH, 'utf8');
}
reject(e);
});
});

View File

@ -16,6 +16,7 @@ const fs = require('fs');
const net = require('net');
const MAX_IDLE_TIME = 30 * 1000;
const MAX_STARTUP_TIME = 5 * 60 * 1000;
class SocketServer {
constructor(sockPath, options) {
@ -43,7 +44,7 @@ class SocketServer {
options.nonPersistent = true;
this._packagerServer = new Server(options);
this._jobs = 0;
this._dieEventually();
this._dieEventually(MAX_STARTUP_TIME);
}
onReady() {
@ -118,7 +119,7 @@ class SocketServer {
}));
}
_dieEventually() {
_dieEventually(delay = MAX_IDLE_TIME) {
clearTimeout(this._deathTimer);
this._deathTimer = setTimeout(() => {
if (this._jobs <= 0 && this._numConnections <= 0) {
@ -126,7 +127,7 @@ class SocketServer {
process.exit();
}
this._dieEventually();
}, MAX_IDLE_TIME);
}, delay);
}
static listenOnServerIPCMessages() {