From 9db0cb49c4a98a25a3ffb74fb8334a8e1f23e1b2 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 22 Sep 2017 11:06:52 -0700 Subject: [PATCH] setTimeout/setImmediate workaround for linux hangs (#1497) FREEBIE --- js/libtextsecure.js | 16 ++++++++++++++++ libtextsecure/api.js | 16 ++++++++++++++++ test/index.html | 1 - 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 86bc299a8..72592fb6e 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -37666,8 +37666,22 @@ var TextSecureServer = (function() { return true; } + // On Linux/Electron multiple quick web requests can result in the Node.js event + // loop getting wedged. Bug: https://github.com/electron/electron/issues/10570 + // This forces the event loop to move. + function scheduleHangWorkaround() { + setTimeout(function() { + setImmediate(function() { + // noop + }); + }, 1000); + } + function createSocket(url) { var requestOptions = { ca: window.config.certificateAuthorities }; + + scheduleHangWorkaround(); + return new nodeWebSocket(url, null, null, null, requestOptions); } @@ -37728,6 +37742,8 @@ var TextSecureServer = (function() { reject(HTTPError(xhr.status, xhr.statusText, options.stack)); }; xhr.send( options.data || null ); + + scheduleHangWorkaround(); }); } diff --git a/libtextsecure/api.js b/libtextsecure/api.js index 1ba44d446..62bb8782b 100644 --- a/libtextsecure/api.js +++ b/libtextsecure/api.js @@ -24,8 +24,22 @@ var TextSecureServer = (function() { return true; } + // On Linux/Electron multiple quick web requests can result in the Node.js event + // loop getting wedged. Bug: https://github.com/electron/electron/issues/10570 + // This forces the event loop to move. + function scheduleHangWorkaround() { + setTimeout(function() { + setImmediate(function() { + // noop + }); + }, 1000); + } + function createSocket(url) { var requestOptions = { ca: window.config.certificateAuthorities }; + + scheduleHangWorkaround(); + return new nodeWebSocket(url, null, null, null, requestOptions); } @@ -86,6 +100,8 @@ var TextSecureServer = (function() { reject(HTTPError(xhr.status, xhr.statusText, options.stack)); }; xhr.send( options.data || null ); + + scheduleHangWorkaround(); }); } diff --git a/test/index.html b/test/index.html index 3217171a6..4aa79da16 100644 --- a/test/index.html +++ b/test/index.html @@ -583,7 +583,6 @@ -