mediasoup3-record-demo
mediasoup3-record-demo copied to clipboard
A bug: GStreamer process doesn't stop when "killed"
When configured with PROCESS_NAME = process.env.PROCESS_NAME || 'FFmpeg'; everything works as expected: the "stop recording" button on the client stops recording and ends the ffmpeg process. However using 'GStreamer', two processes are created: one the actual gst-launch-1.0, and the other - /bin/sh, apparently due to shell: true in spawn(). When the parent process wants to kill the child, it uses a PID of the shell and the process is not killed, but continues to run.
on ios device
I think this occurs on linux? I can't reproduce it on my local mac. Will look into it, can you tell me the OS of the server?
same to me.
I can reproduce it on ubuntu 18.04.
According to https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal
On Linux, child processes of child processes will not be terminated when attempting to kill their parent. This is likely to happen when running a new process in a shell or with the use of the shell option of ChildProcess
in gstream file add this code
kill () { console.log('kill() [pid:%d]', this._process.pid); this._process.kill('SIGINT'); this.killSubprocesses(this._process.pid) }
killSubprocesses(pid) {
try {
const output = require('child_process').execSync(pgrep -P ${pid}
).toString();
const pids = output.trim().split('\n');
pids.forEach(subpid => {
process.kill(subpid, 'SIGTERM'); // Send SIGTERM signal to subprocess
killSubprocesses(subpid); // Recursively kill subprocesses of subprocess
});
} catch (err) {
// Ignore errors
}
}