1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

prevent listener stacking on error

Fix error ```MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process].```
This commit is contained in:
Amateur Audio Dude
2025-09-07 02:36:08 +10:00
committed by GitHub
parent 70e8295831
commit 7487825fd3

View File

@@ -237,6 +237,17 @@ checkFFmpeg().then((ffmpegPath) => {
commandDef.args.splice(commandDef.recArgs.indexOf('pipe:1'), 0, '-af', 'volume=2.5');
}
let currentRec = null;
process.on('exit', () => {
if (currentRec) currentRec.kill('SIGINT');
});
process.on('SIGINT', () => {
if (currentRec) currentRec.kill('SIGINT');
process.exit();
});
function startRec() {
if (!serverConfig.audio.ffmpeg) {
// Spawn rec
@@ -244,6 +255,7 @@ checkFFmpeg().then((ffmpegPath) => {
//const rec = spawn(commandDef.command, { shell: true, stdio: ['ignore', 'pipe', 'pipe'] });
const rec = spawn('rec', commandDef.recArgs, { stdio: ['ignore', 'pipe', 'pipe'] });
currentRec = rec;
audioServer.waitUntilReady.then(() => {
audioServer.Server.StdIn = rec.stdout;
@@ -251,15 +263,6 @@ checkFFmpeg().then((ffmpegPath) => {
connectMessage(`${consoleLogTitle} Connected rec \u2192 FFmpeg \u2192 Server.StdIn${serverConfig.audio.audioBoost && serverConfig.audio.ffmpeg ? ' (audio boost)' : ''}`);
});
process.on('exit', () => {
rec.kill('SIGINT');
});
process.on('SIGINT', () => {
rec.kill('SIGINT');
process.exit();
});
rec.stderr.on('data', (data) => {
logFfmpeg(`[rec stderr]: ${data}`);
});
@@ -317,6 +320,17 @@ checkFFmpeg().then((ffmpegPath) => {
commandDef.args.splice(commandDef.args.indexOf('pipe:1'), 0, '-af', 'volume=2.5');
}
let currentArecord = null;
process.on('exit', () => {
if (currentArecord) currentArecord.kill('SIGINT');
});
process.on('SIGINT', () => {
if (currentArecord) currentArecord.kill('SIGINT');
process.exit();
});
function startArecord() {
if (!serverConfig.audio.ffmpeg) {
// Spawn the arecord loop
@@ -324,6 +338,7 @@ checkFFmpeg().then((ffmpegPath) => {
//const arecord = spawn(commandDef.command, { shell: true, stdio: ['ignore', 'pipe', 'pipe'] });
const arecord = spawn('arecord', commandDef.arecordArgs, { stdio: ['ignore', 'pipe', 'pipe'] });
currentArecord = arecord;
audioServer.waitUntilReady.then(() => {
audioServer.Server.StdIn = arecord.stdout;
@@ -331,15 +346,6 @@ checkFFmpeg().then((ffmpegPath) => {
connectMessage(`${consoleLogTitle} Connected arecord \u2192 FFmpeg \u2192 Server.StdIn${serverConfig.audio.audioBoost && serverConfig.audio.ffmpeg ? ' (audio boost)' : ''}`);
});
process.on('exit', () => {
arecord.kill('SIGINT');
});
process.on('SIGINT', () => {
arecord.kill('SIGINT');
process.exit();
});
arecord.stderr.on('data', (data) => {
logFfmpeg(`[arecord stderr]: ${data}`);
});