From 2727f4b5ea0ecacbb28c679d4bda656bdfa8a0b1 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Mon, 7 Sep 2015 10:44:02 -0700 Subject: [PATCH] [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 --- react-packager/src/SocketInterface/SocketClient.js | 8 +++++++- react-packager/src/SocketInterface/SocketServer.js | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/react-packager/src/SocketInterface/SocketClient.js b/react-packager/src/SocketInterface/SocketClient.js index 6ccfd481..32e3b25d 100644 --- a/react-packager/src/SocketInterface/SocketClient.js +++ b/react-packager/src/SocketInterface/SocketClient.js @@ -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); }); }); diff --git a/react-packager/src/SocketInterface/SocketServer.js b/react-packager/src/SocketInterface/SocketServer.js index abdc094b..888dcf78 100644 --- a/react-packager/src/SocketInterface/SocketServer.js +++ b/react-packager/src/SocketInterface/SocketServer.js @@ -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() {