From 9c322df7b8ffa7c1467ebafe9b278eaa78bd1b29 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Thu, 26 Nov 2015 10:07:12 -0800 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20do=20manual=20connection=20coun?= =?UTF-8?q?ting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed By: tadeuzagallo Differential Revision: D2696017 fb-gh-sync-id: 039abf9b7ed1570590e96e7077bb48a5493e8471 --- .../src/SocketInterface/SocketServer.js | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packager/react-packager/src/SocketInterface/SocketServer.js b/packager/react-packager/src/SocketInterface/SocketServer.js index 56562e273..2e5335270 100644 --- a/packager/react-packager/src/SocketInterface/SocketServer.js +++ b/packager/react-packager/src/SocketInterface/SocketServer.js @@ -52,13 +52,11 @@ class SocketServer { setImmediate(() => process.exit(1)); }); - this._numConnections = 0; this._server.on('connection', (sock) => this._handleConnection(sock)); // Disable the file watcher. options.nonPersistent = true; this._packagerServer = new Server(options); - this._jobs = 0; this._dieEventually(MAX_STARTUP_TIME); } @@ -68,8 +66,6 @@ class SocketServer { _handleConnection(sock) { debug('connection to server', process.pid); - this._numConnections++; - sock.on('close', () => this._numConnections--); const bunser = new bser.BunserBuf(); sock.on('data', (buf) => bunser.append(buf)); @@ -95,7 +91,6 @@ class SocketServer { const handleError = (error) => { debug('request error', error); - this._jobs--; this._reply(sock, m.id, 'error', error.stack); // Fatal error from JSTransformer transform workers. @@ -106,7 +101,6 @@ class SocketServer { switch (m.type) { case 'getDependencies': - this._jobs++; this._packagerServer.getDependencies(m.data).then( ({ dependencies }) => this._reply(sock, m.id, 'result', dependencies), handleError, @@ -114,7 +108,6 @@ class SocketServer { break; case 'buildBundle': - this._jobs++; this._packagerServer.buildBundle(m.data).then( (result) => this._reply(sock, m.id, 'result', result), handleError, @@ -122,7 +115,6 @@ class SocketServer { break; case 'buildPrepackBundle': - this._jobs++; this._packagerServer.buildPrepackBundle(m.data).then( (result) => this._reply(sock, m.id, 'result', result), handleError, @@ -130,7 +122,6 @@ class SocketServer { break; case 'getOrderedDependencyPaths': - this._jobs++; this._packagerServer.getOrderedDependencyPaths(m.data).then( (dependencies) => this._reply(sock, m.id, 'result', dependencies), handleError, @@ -156,17 +147,19 @@ class SocketServer { // Debounce the kill timer to make sure all the bytes are sent through // the socket and the client has time to fully finish and disconnect. this._dieEventually(); - this._jobs--; } _dieEventually(delay = MAX_IDLE_TIME) { clearTimeout(this._deathTimer); this._deathTimer = setTimeout(() => { - if (this._jobs <= 0 && this._numConnections <= 0) { - debug('server dying', process.pid); - process.exit(); - } - this._dieEventually(); + this._server.getConnections((error, numConnections) => { + // error is passed when connection count is below 0 + if (error || numConnections <= 0) { + debug('server dying', process.pid); + process.exit(); + } + this._dieEventually(); + }); }, delay); }