You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Media Player leaks pipe FDs on file switches #1044
The Media Player leaks file descriptors on file switches. While soaking the storm test for #996 with STROM_STORM_CALLS=10000, the test process grew by about 170 pipe FDs a second. These were GstPoll/GWakeup pipes, which means bins created for each file are not being finalized. After about 40 s it aborted:
GLib-ERROR: Creating pipes for GWakeup: Too many open files
The default storm (3000 calls) stays under the limit, so CI does not see it.
Why it may matter in production
A file switch in production takes the same path as in the storm: load_current_file_inner takes the internal pipeline to READY, sets a new uri on the source, and starts it again. uridecodebin3 then builds a new urisourcebin, typefind, parsebin and decoders. If those bins are the ones not finalized, then a looping playlist of short clips, or an operator stepping through clips, leaks on every switch.
FDs: one or two per leaked GstPoll. On Docker/Linux with a high nofile limit that takes a long time to hit. The native macOS app often runs with a much lower limit.
Memory: if parsebin and decoders are not finalized, their buffer pools leak too. That could grow faster than the FD count. Not measured.
Not known yet
Whether a calm switch leaks, or only a switch interrupted mid state change (which the storm does all the time, and production rarely does).
Where the reference is held. The Media Player's own closures (connect_pad_added in bridge.rs, hold_typefind_while_starting) capture only weak references, which points at something else holding the bins, possibly inside GStreamer. Not checked.
Next
Measure a calm playlist: switch files once a second for a few minutes, with no pauses, and record the process FD count and RSS over time. Do the same with the storm to compare.
If a calm switch leaks, find what holds the old bins (GST_TRACERS=leaks, or refcount logging on the urisourcebin/parsebin children) and add a guard test that fails if the FD count grows across N switches.
Area: Media Player file switching, object lifetimes
About: Under the storm test, file switches leak pipe FDs (GstPoll wakeups), which means the per-file bins are not finalized. Two things are unknown: whether a calm switch leaks too, and what holds the bins. The player's own handlers capture only weak references, so the reference may sit elsewhere, possibly inside GStreamer.
Relates to: merged #996 (the storm test that found it). #953 is the same shape in another block: a removed bin left above NULL after an interrupted state change. Merged #1072 and #1076 changed the same switch path since this was filed.
Thoughts: First, measure FDs and RSS over calm switches, one a second for a few minutes. That says whether production playlists are hit. Then a leaks tracer snapshot shows whose layer holds the bins.
Findings: the FD leak is macOS-only, and only in a process with no main run loop
What leaks
No bins. A leaks tracer snapshot after 100 fast switches on macOS (GStreamer 1.28.6) shows exactly one live GstGLWindowCocoa per switch and nothing else of note. Each window owns a GMainContext, whose wakeup is a pipe pair. Those are the 2 FDs per switch.
Why
On macOS decodebin3 picks vtdec, which outputs GL memory and makes its own GL context (only the GL display is shared through the pipeline, the context is not).
Calm switches: the previous context is still alive, kept by buffers in flight, so each new vtdec reuses it. One context for the whole run.
Fast switches: the old decoder and its context are gone before the new vtdec negotiates, so every switch creates a new GL context and a new Cocoa window. The contexts finalize, but the window is released through the main dispatch queue. A test process does not service that queue, so the window is never freed.
Strom runs a Cocoa run loop on the main thread in production: gstreamer::macos_main in headless mode, winit in GUI mode. There the windows are released.
Measurements
Media Player in a real flow, video_out into a fakesink, H.264 MP4 clips, open FDs counted from /dev/fd:
Setup
Switches
FDs
macOS, 500 ms between switches
30
flat at 24
macOS, back to back
600
16 → 1220
macOS, back to back with pauses
600
16 → 820
Linux (Ubuntu 24.04, GStreamer 1.24.2), back to back, avdec_h264
600
28 → 29–31, 24 after stop
Linux, same, NVDEC ranked out as in CI
600
28 → 29–35, 24 after stop
Linux, back to back with pauses
600
28 → 31–35, 24 after stop
Pure GStreamer repro, no Strom code (uridecodebin3 ! fakesink, READY → set uri → PLAYING, 100 times):
Setup
FDs
macOS, no main run loop
8 → 213
macOS, CFRunLoop running on the main thread
8 → 11
Linux container, GStreamer 1.24.2
8 → 6
A separate small leak on Linux
On the Linux host (GStreamer 1.24.2) the leaks tracer shows one GstStream per file switch still alive after the flow stops, each with its caps, tag list and a small buffer. It happens on calm switches too: 20 switches 500 ms apart left 20 streams. This is a memory leak of a few KB per switch, not FDs. The macOS run on GStreamer 1.28.6 showed no live GstStreams, which points at a GStreamer 1.24 issue fixed later. This is not confirmed on 1.28 under Linux.
Suggested next steps
The FD part needs no change in the player. A guard test for FD growth would hold on Linux and Windows; on macOS it needs a main run loop in the test process, or the internal pipeline keeping its GL context across switches. The latter would also save a GL context, thread and window per fast switch.
Check the GstStream leak on GStreamer 1.28 under Linux before deciding whether it needs a fix in Strom.
Activity
srperens commentedon Oct 16, 2026
Area: Media Player file switching, object lifetimes
About: Under the storm test, file switches leak pipe FDs (GstPoll wakeups), which means the per-file bins are not finalized. Two things are unknown: whether a calm switch leaks too, and what holds the bins. The player's own handlers capture only weak references, so the reference may sit elsewhere, possibly inside GStreamer.
Relates to: merged #996 (the storm test that found it). #953 is the same shape in another block: a removed bin left above NULL after an interrupted state change. Merged #1072 and #1076 changed the same switch path since this was filed.
References: GStreamer leaks tracer
Thoughts: First, measure FDs and RSS over calm switches, one a second for a few minutes. That says whether production playlists are hit. Then a
leakstracer snapshot shows whose layer holds the bins.srperens commentedon Oct 28, 2026
Findings: the FD leak is macOS-only, and only in a process with no main run loop
What leaks
No bins. A
leakstracer snapshot after 100 fast switches on macOS (GStreamer 1.28.6) shows exactly one liveGstGLWindowCocoaper switch and nothing else of note. Each window owns aGMainContext, whose wakeup is a pipe pair. Those are the 2 FDs per switch.Why
On macOS decodebin3 picks
vtdec, which outputs GL memory and makes its own GL context (only the GL display is shared through the pipeline, the context is not).vtdecreuses it. One context for the whole run.vtdecnegotiates, so every switch creates a new GL context and a new Cocoa window. The contexts finalize, but the window is released through the main dispatch queue. A test process does not service that queue, so the window is never freed.Strom runs a Cocoa run loop on the main thread in production:
gstreamer::macos_mainin headless mode, winit in GUI mode. There the windows are released.Measurements
Media Player in a real flow,
video_outinto a fakesink, H.264 MP4 clips, open FDs counted from/dev/fd:avdec_h264Pure GStreamer repro, no Strom code (
uridecodebin3 ! fakesink, READY → set uri → PLAYING, 100 times):CFRunLooprunning on the main threadA separate small leak on Linux
On the Linux host (GStreamer 1.24.2) the
leakstracer shows oneGstStreamper file switch still alive after the flow stops, each with its caps, tag list and a small buffer. It happens on calm switches too: 20 switches 500 ms apart left 20 streams. This is a memory leak of a few KB per switch, not FDs. The macOS run on GStreamer 1.28.6 showed no liveGstStreams, which points at a GStreamer 1.24 issue fixed later. This is not confirmed on 1.28 under Linux.Suggested next steps
GstStreamleak on GStreamer 1.28 under Linux before deciding whether it needs a fix in Strom.