Skip to content

Media Player leaks pipe FDs on file switches #1044

Open

Description

@srperens

Written by Claude (AI), from a finding in #996.

What happens

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

  1. 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.
  2. 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.

Activity

  1. srperens commented on Oct 16, 2026

    @srperens
    CollaboratorAuthor

    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 leaks tracer snapshot shows whose layer holds the bins.

  2. srperens commented on Oct 28, 2026

    @srperens
    CollaboratorAuthor

    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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    LowPriority: lowbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions