Skip to content

Fix detection of go2rtc process death and clarify logging#378

Merged
matteius merged 1 commit intoopensensor:mainfrom
dpw13:fix/go2rtc-forking
Apr 13, 2026
Merged

Fix detection of go2rtc process death and clarify logging#378
matteius merged 1 commit intoopensensor:mainfrom
dpw13:fix/go2rtc-forking

Conversation

@dpw13
Copy link
Copy Markdown
Contributor

@dpw13 dpw13 commented Apr 12, 2026

This PR fixes a few issues:

  • Checking for a running process using kill works fine as long as you're reaping the child process beforehand. That wasn't being done so a zombie go2rtc process was considered alive.
  • If you run ./build/Release/bin/lightnvr from the root of the repo and go2rtc is not installed, the current code finds the go2rtc directory and thinks that's a working executable. Check that the resolved go2rtc is a file and not a directory or something else.
  • The logging around finding go2rtc in PATH seemed to indicate that it was found even when it wasn't. Clean up that code path and clarify the logging.
  • If go2rtc lives long enough to pass the first check but dies after that, the code will continue attempting to connect even though go2rtc is dead. Check that the process is still running in the reconnect loop.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves robustness of the embedded go2rtc process management by tightening executable discovery/validation and improving detection of unexpected process termination during startup.

Changes:

  • Make PATH resolution stricter by requiring the candidate to be a regular file (not a directory) and returning an empty result when not found.
  • Clarify logging for the “not found in PATH” case.
  • Reap zombie children and re-check liveness during the API readiness loop to avoid treating a dead go2rtc as running.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dpw13 dpw13 force-pushed the fix/go2rtc-forking branch from 4a0e121 to 8493848 Compare April 13, 2026 16:03
@dpw13
Copy link
Copy Markdown
Contributor Author

dpw13 commented Apr 13, 2026

Good to re-review!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 955 to 957
// Reap any existing zombie children first
reap_zombie_children();
reap_zombie_children(WAIT_ANY);

Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reap_zombie_children(WAIT_ANY) calls waitpid(-1, …) and will reap all exited children for the entire program, not just go2rtc. This can still interfere with other subsystems that expect to waitpid() their own child processes. Prefer reaping only the go2rtc PID(s) you created/managed here, or remove this global reap and rely on the targeted waits already used in the kill/wait flow.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm making a judgement call to leave this specific instance in, as it's what the original code was doing. If I get a chance to review the shutdown of other subprocesses and threads, I may revisit this.

* clarify logging around binary not found
* check that go2rtc binary is a real file before execl()
* consolidate signalling processes and reaping children
@dpw13 dpw13 force-pushed the fix/go2rtc-forking branch from 8493848 to 9456ee5 Compare April 13, 2026 17:03
@matteius matteius merged commit 4a3911b into opensensor:main Apr 13, 2026
1 check passed
@dpw13 dpw13 deleted the fix/go2rtc-forking branch April 13, 2026 17:04
@dpw13
Copy link
Copy Markdown
Contributor Author

dpw13 commented Apr 13, 2026

🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants