Skip to content

Commit

Permalink
Kill any processes started by coapp on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Oct 18, 2023
1 parent 3086ee9 commit 072987d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import open from 'open';

const os = require("os");
const path = require('path');
const { spawn } = require('child_process');

const logger = require('./logger');
const rpc = require('./weh-rpc');
Expand All @@ -16,6 +15,27 @@ if (os.platform() == "win32") {
ffprobe += ".exe";
}

// Record all started processes, and kill them if the coapp
// ends, crash or is killed by the browser.
let to_kill = new Set();
function spawn(arg0, argv) {

Check failure on line 21 in app/src/converter.js

View workflow job for this annotation

GitHub Actions / build

Expected blank line before this statement
const { spawn } = require('child_process');
let process = spawn(arg0, argv);
if (process.pid) {
to_kill.add(process);
process.on("exit", () => to_kill.delete(process));
}
return process;
}
for (let e of ["exit", "SIGINT", "SIGTERM", "uncaughtException"]) {

Check failure on line 30 in app/src/converter.js

View workflow job for this annotation

GitHub Actions / build

Expected blank line before this statement
process.on(e, () => {
for (let process of to_kill) {
try { process.kill(9); } catch (_) { /* */ }

Check failure on line 33 in app/src/converter.js

View workflow job for this annotation

GitHub Actions / build

Statement inside of curly braces should be on next line

Check failure on line 33 in app/src/converter.js

View workflow job for this annotation

GitHub Actions / build

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
}
process.exit(0);
});
}

function ExecConverter(args) {
return new Promise((resolve, reject) => {
let convProcess = spawn(ffmpeg, args);
Expand Down

0 comments on commit 072987d

Please sign in to comment.