Repository navigation
Remove the GStreamer bus watch when a pipeline is destroyed - #36
Merged
Merged
Conversation
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.
sjmiller609
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
TestDestroyClosesPipelineFileswarms up GStreamer, runs ten pipelines, and checks the process's file descriptor count. Onmasterthose ten pipelines left 20 descriptors open. With this change the count did not grow.go test -race -count=20 ./pkg/gstpassed with GStreamer 1.28.2.go vet ./pkg/gstpassed.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_destorynow 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.