From 6665c4693f2b677e4bc9b7aef5f6c3d71ef77e1c Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 24 Nov 2020 00:21:57 -0500 Subject: [PATCH] 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. --- src/node/utils/LibreOffice.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node/utils/LibreOffice.js b/src/node/utils/LibreOffice.js index 39bce5b4d..6ed28210e 100644 --- a/src/node/utils/LibreOffice.js +++ b/src/node/utils/LibreOffice.js @@ -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}`);