Skip to content

Remove the GStreamer bus watch when a pipeline is destroyed - #36

Merged
yummybomb merged 1 commit into
masterfrom
hypeship/release-gst-bus-watch
Nov 18, 2026
Merged

yummybomb merged 1 commit into
masterfrom
hypeship/release-gst-bus-watch

Conversation

@yummybomb

@yummybomb yummybomb commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

Each capture pipeline adds a watch to its GStreamer bus. Destroying the pipeline didn't remove the watch, so the bus and the two file descriptors for its control socket pair stayed alive. A viewer who starts and stops both audio and video leaves four descriptors behind, even on a normal disconnect.

Remove the watch during pipeline teardown. This is independent of the WebRTC peer cleanup in #33 and can land first.

Testing

  • TestDestroyClosesPipelineFiles warms up GStreamer, runs ten pipelines, and checks the process's file descriptor count. On master those ten pipelines left 20 descriptors open. With this change the count did not grow.
  • go test -race -count=20 ./pkg/gst passed with GStreamer 1.28.2. go vet ./pkg/gst passed.
  • In the earlier combined viewer tests, the server had 103 open files after 20 viewers without the fix versus 23 with it. The package test above checks this change in isolation.

Note

Medium Risk
Teardown order in native GStreamer code affects long-lived viewers; incorrect bus handling could regress shutdown, but the change is narrowly scoped with a regression test for FD leaks.

Overview
Fixes a file descriptor leak when capture pipelines are torn down: gstreamer_pipeline_destory now removes the bus watch and unrefs the bus after stopping the pipeline, so the bus and its control-socket FDs are not kept alive after destroy.

Adds TestDestroyClosesPipelineFiles, which warms GStreamer once, runs ten create/play/destroy cycles, and asserts the process FD count does not grow.

Reviewed by Cursor Bugbot for commit 7c3ebdc. Bugbot is set up for automated code reviews on this repo. Configure here.

The watch added for every pipeline was never removed. It holds a
reference to the pipeline's bus, so each destroyed pipeline left its bus
and the two sockets of the bus's control socket pair behind.
@yummybomb
yummybomb marked this pull request as ready for review November 18, 2026 19:09
@yummybomb
yummybomb merged commit 5aee0d2 into master Nov 18, 2026
4 checks passed
@yummybomb
yummybomb deleted the hypeship/release-gst-bus-watch branch November 18, 2026 21:00
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.

2 participants