mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-13 22:29:45 +08:00
Don’t do manual connection counting
Reviewed By: tadeuzagallo Differential Revision: D2696017 fb-gh-sync-id: 039abf9b7ed1570590e96e7077bb48a5493e8471
This commit is contained in:
committed by
facebook-github-bot-4
parent
c4636beaeb
commit
9c322df7b8
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user