Skip to content

bug: vlc-video: Stop near a playlist track boundary can take up to 3 s (drain_abort reset races the stop) #1011

Closed

Description

@zackees

Found while looking at test_vlc_playlist_gap's stop_at_track_end_is_prompt failure listed on #838 (merge-group run 38850208674, Rust Tier 2 Linux ON): stopping at the end of a track took 2.068 s (state 1). State 1 is PLAYING and 2.068 s is where the test gives up (1000 × 2 ms), so the stop had not taken effect at all. That is not "slow under load" like the other #838 cases.

Location

plugins/vlc-video/vlc-video-source.c

  • drain_abort is a manual-reset event. vlcs_stop (and restart/next/prev/update/destroy) calls abort_drain (signal) so that vlcs_audio_play's pacing wait and vlcs_audio_drain (each up to MAX_DRAIN_MS = 3000 ms, on libVLC's audio thread) end at once, then calls libvlc_media_list_player_stop_, which waits for that thread.
  • vlcs_started does os_event_reset(c->drain_abort). It is attached to libvlc_MediaPlayerOpening (:1036), which libVLC fires on its event thread when the next playlist item opens, i.e. at a track boundary.
  • obs_source_media_stop queues MEDIA_ACTION_STOP; vlcs_stop runs on a later tick.

Race

Stop near a track boundary: vlcs_stop signals drain_abort, the next item's Opening event resets it right after, libVLC's audio thread re-enters a pacing/drain wait for up to 3 s, and libvlc_media_list_player_stop_ blocks behind it. The source still reports PLAYING meanwhile. Load makes that interleaving more likely, so it shows up as a flake in the merge queue (it removed #936 once).

Class

Race (stop not honored); user-visible as Stop/hotkey taking up to 3 s on a playlist.

Proposed fix

Do not let an asynchronous libVLC event undo a stop. E.g. an atomic stop_requested set by abort_drain callers that stop (and cleared by the calls that start playback: play, restart, update), with vlcs_started resetting drain_abort only when no stop is pending; or reset the event only from the OBS-side calls that start playback, never from the libVLC event thread.

Test

The ordering is not controllable from outside, so: a stress case (stop exactly at item boundaries, repeated) that fails before the fix, plus a deterministic unit test of the abort/reset logic once it is factored into a small helper. Refs #838, #301.

Activity

  1. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    Claiming: confirm with a repeated boundary-stop run, then fix as above (RED then GREEN).

  2. added
    bug
    claimed
    on Oct 16, 2026
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

    bugclaimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions