mediasoup3-record-demo icon indicating copy to clipboard operation
mediasoup3-record-demo copied to clipboard

A bug: GStreamer process doesn't stop when "killed"

Open alexfreed58 opened this issue 4 years ago • 4 comments

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.

alexfreed58 avatar Dec 08 '20 01:12 alexfreed58

on ios device

conandark avatar Dec 20 '20 18:12 conandark

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?

ethand91 avatar Feb 17 '21 05:02 ethand91

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

Leegorous avatar Mar 02 '21 02:03 Leegorous

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 } }

snowflaxGitRepo avatar Apr 05 '24 07:04 snowflaxGitRepo