Clear hang timeout timer when LibreOffice exits

This prevents `npm test` from freezing for two minutes after the tests
complete.

Also switch to an arrow function for the `setTimeout` callback.
This commit is contained in:
Richard Hansen 2020-11-24 00:21:57 -05:00 committed by John McLear
parent 029f2f765e
commit 6665c4693f
1 changed files with 2 additions and 1 deletions

View File

@ -91,7 +91,7 @@ function doConvertTask(task, callback) {
]);
// Soffice/libreoffice is buggy and often hangs.
// To remedy this we kill the spawned process after a while.
setTimeout(function(){
const hangTimeout = setTimeout(() => {
soffice.stdin.pause(); // required to kill hanging threads
soffice.kill();
}, 120000);
@ -109,6 +109,7 @@ function doConvertTask(task, callback) {
});
soffice.on('exit', function(code) {
clearTimeout(hangTimeout);
if (code != 0) {
// Throw an exception if libreoffice failed
return callback(`LibreOffice died with exit code ${code} and message: ${stdoutBuffer}`);