Skip to content

Commit

Permalink
Merge pull request #178 from aclap-dev/kill_ffmpeg
Browse files Browse the repository at this point in the history
Kill any processes started by coapp on exit
  • Loading branch information
mi-g committed Oct 18, 2023
2 parents 3086ee9 + e6a4fb9 commit a72c166
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ jobs:
- run: eslint app tests/*.mjs
- run: sudo snap install yq
- run: ./build.sh
- run: sudo dpkg -i ./dist/linux/x86_64/vdhcoapp-2.0.3-linux-x86_64.deb
- run: sudo dpkg -i ./dist/linux/x86_64/vdhcoapp-2.0.4-linux-x86_64.deb
- run: ./tests/test.mjs /opt/vdhcoapp/vdhcoapp --with-network
28 changes: 27 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,33 @@ if (os.platform() == "win32") {
ffprobe += ".exe";
}

// Record all started processes, and kill them if the coapp
// ends, crashes or is killed by the browser.
let to_kill = new Set();

function spawn(arg0, argv) {
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"]) {
process.on(e, () => {
for (let process of to_kill) {
try {
process.kill(9);
} catch (_) {
/* */
}
}
process.exit(0);
});
}

function ExecConverter(args) {
return new Promise((resolve, reject) => {
let convProcess = spawn(ffmpeg, args);
Expand Down
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id = "net.downloadhelper.coapp"
name = "VdhCoApp"
long_name = "DownloadHelper CoApp"
description = "Video DownloadHelper companion app"
version = "2.0.3"
version = "2.0.4"

[package]
binary_name = "vdhcoapp" # .exe added automatically
Expand Down

0 comments on commit a72c166

Please sign in to comment.