Skip to content

Commit

Permalink
setTimeout/setImmediate workaround for linux hangs (#1497)
Browse files Browse the repository at this point in the history
FREEBIE
  • Loading branch information
scottnonnenberg authored Sep 22, 2017
1 parent 42f2142 commit 9db0cb4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions js/libtextsecure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -37728,6 +37742,8 @@ var TextSecureServer = (function() {
reject(HTTPError(xhr.status, xhr.statusText, options.stack));
};
xhr.send( options.data || null );

scheduleHangWorkaround();
});
}

Expand Down
16 changes: 16 additions & 0 deletions libtextsecure/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -86,6 +100,8 @@ var TextSecureServer = (function() {
reject(HTTPError(xhr.status, xhr.statusText, options.stack));
};
xhr.send( options.data || null );

scheduleHangWorkaround();
});
}

Expand Down
1 change: 0 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ <h3>{{ message }}</h3>
<script type="text/javascript" src="../js/storage.js" data-cover></script>
<script type="text/javascript" src="../js/signal_protocol_store.js" data-cover></script>
<script type="text/javascript" src="../js/libtextsecure.js" data-cover></script>
<script type="text/javascript" src="../js/backup.js" data-cover></script>

<script type="text/javascript" src="../js/libphonenumber-util.js"></script>
<script type="text/javascript" src="../js/models/messages.js" data-cover></script>
Expand Down

0 comments on commit 9db0cb4

Please sign in to comment.