From c1c61a4e88bc44d9f7bc38d7a022203ec0575d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Tue, 15 Sep 2015 16:18:17 -0700 Subject: [PATCH] defeat race condition when replying to client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: @​public The server dies after 30 seconds if it has no jobs on it's queue. The problem is that the jobs counter gets decreased before returning the bytes to the client. As a consequence, it's possible that the server dies while it's returning the bytes to the client, or just after it finished returning the bytes to the client. To avoid both issues lets move the counter decrease a few lines below and bump the timer to make sure we have time to fully write the bytes on the socket and let the client close the connection before the server dies. Reviewed By: @vjeux Differential Revision: D2445264 --- react-packager/src/SocketInterface/SocketServer.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/react-packager/src/SocketInterface/SocketServer.js b/react-packager/src/SocketInterface/SocketServer.js index 19b4b29c..8c32db40 100644 --- a/react-packager/src/SocketInterface/SocketServer.js +++ b/react-packager/src/SocketInterface/SocketServer.js @@ -114,7 +114,6 @@ class SocketServer { _reply(sock, id, type, data) { debug('request finished', type); - this._jobs--; data = toJSON(data); sock.write(bser.dumpToBuffer({ @@ -122,6 +121,11 @@ class SocketServer { type, data, })); + + // 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) {