Repository navigation
Description
Found by our own load testing of test_vlc_playlist_gap (the stop_at_track_end_is_prompt guard from #1037), not reported upstream. Upstream OBS has the same code: vlcs_stop() calls libvlc_media_list_player_stop() with no regard for libVLC's playlist thread. Two intermittent failures of that guard turned out to be one bug:
- the Stop took 2.04 s and the source was still PLAYING (1 in 240 runs, C libobs lane; 1 in 200, hybrid lane);
- the test process died with SIGABRT and no message (1 in 56 runs, then 1 in 200, hybrid lane; the same abort happens in the C lane).
Location
- libVLC 3.0.x,
lib/media_list_player.c: after the end of a track (libvlc_MediaPlayerEndReached),media_player_reached_end()bumpsseek_offsetand wakesplaylist_thread, which moves to the next item holding onlymp_callback_lock.set_current_playing_item()detaches and re-attaches the list player's end-of-track listener, anduninstall_media_player_observer()dropsmp_callback_lockwhile it detaches. libvlc_media_list_player_stop()→stop()takes the object lock andmp_callback_lock, then calls the sameuninstall_media_player_observer(), which dropsmp_callback_lockfor its own detach.stop()doesn't clearseek_offset, and it sets the current item path to NULL.plugins/vlc-video/vlc-video-source.c.h:vlcs_stop(),vlcs_restart(),vlcs_update(),vlcs_deactivate(),vlcs_destroy()and next/previous call the list player directly, so any of them can meet that move.
Class
Crash (abort() in libVLC) and a lost Stop. One race, two outcomes:
- The move runs after the Stop. With the path reset to NULL, libVLC starts the first item again, then the next one. The source stays PLAYING, and because vlc-video: Keep a Stop in force when the next playlist item opens #1037 keeps the audio-wait gate open while a Stop is pending, those items play without pacing: their audio is handed to libobs about a second early (in the log, a timestamp jump of −1.07 s).
- The move and the Stop each detach the same listener. The second
libvlc_event_detach()finds nothing and callsabort().
Backtrace (both libobs lanes, libVLC 3.0.24):
Thread "test_vlc_playli" (libVLC playlist thread):
#6 abort ()
#7 libvlc.so.5 +0x906f libvlc_event_detach: listener not found -> abort()
#8 libvlc.so.5 +0x1ded8 playlist_thread -> set_current_playing_item -> uninstall_media_player_observer
Thread "libobs: graphics":
libvlc_media_player_stop <- libvlc_media_list_player_stop <- vlcs_stop <- process_media_actions <- obs_source_video_tick
It is not a Rust panic or a C assert. The hybrid lane only shows it more often.
How it is reached
A VLC Video Source with a playlist of two or more items: press Stop (or Restart, change a setting, hide it with "Stop when not visible", remove it, or press Next/Previous) in the few milliseconds around a track end. A playlist of short files makes the window come up often. obs-websocket's TriggerMediaInputAction reaches the same calls.
Reproduced
Headless (private Xvfb, private D-Bus, fresh HOME), libVLC 3.0.24.
| Build | Case | Result |
|---|---|---|
| master dd8a7a6 + test only, C lane | stop_at_track_end_is_prompt, 240 runs under load |
1 Stop took 2.04 s, still PLAYING |
| master + test only, hybrid lane | same, 200 runs under load | 1 Stop took 2.12 s, still PLAYING; 1 SIGABRT (backtrace above) |
| master + new case, both lanes | Stop sent from the media_ended handler, report held 150 ms |
6 runs: 1 lost Stop (PLAYING, an item started after the Stop), 5 SIGABRT |
The current release ships the same vlcs_stop(). I didn't drive the AppImage to a track end by hand, because the window is too narrow.
Fix
Keep the source's list-player calls from meeting libVLC's move. The source marks the move as under way on the end-of-track event, and as done on the list player's NextItemSet, Played or Stopped event. Before it stops, it stops the media player first. That ends the track's input thread, so no further end-of-track report can come. It then waits up to 1 s for a move that is under way to finish, and repeats if that move started an item. Only then does it call the list player's stop, which stops whatever the move started. Next and previous wait for a move under way too. An item that opens while a Stop is pending doesn't emit media_started, and its audio is dropped. PR follows.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
test: A VLC Stop as a playlist track ends must stay in force
vlc-video: Let libVLC's playlist move finish before stopping
vlc-video: Let libVLC's playlist move finish before stopping
vlc-video: Let libVLC's playlist move finish before stopping (obs-rus…