TSan detected data race in unref_image

Aperta
#18,807 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
47/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, macos
Ambito
backend

Direzione di ricerca

Start with unref_image and mp_image_pool_get_no_alloc, named in the ThreadSanitizer report, then trace how decoder shutdown in flush_all overlaps with buffer access on worker threads. Reproduce with a ThreadSanitizer build and the provided H.264 sample. Done when the race is understood and corrected, and ThreadSanitizer no longer reports it when quitting playback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

os:mac
mpv Information
mpv v0.42.0-36-gd075ec2a2 Copyright © 2000-2026 mpv/MPlayer/mplayer2 projects
 built on Nov 10 2026 09:07:29
libplacebo version: v7.391.0 (v7.387.0-37-gc2cf6e72)
FFmpeg version: n9.0.2
FFmpeg library versions:
   libavcodec      63.1.102
   libavdevice     63.1.102
   libavfilter     12.1.102
   libavformat     63.1.102
   libavutil       61.1.102
   libswresample   7.1.102
   libswscale      10.1.102
Other Information
- macOS version: macOS 27.2 (26B123)
- Source of mpv: Local build
- Latest known working version: Unknown
- Issue started after the following happened: I built with TSan
Reproduction Steps
  • Download a H.264 encoded copy of Big Buck Bunny from here using this link

  • Use mpv-build to build mpv with TSan enabled:

    • Save any existing mpv_options file you already have

    • Run the following commands in Terminal to configure mpv-build to build with the ThreadSanitizer enabled:

      printf "%s\n" -Dbuildtype=debug > mpv_options
      printf "%s\n" -Db_sanitize=thread >> mpv_options

    • Build mpv

  • Play the downloaded video with mpv built with TSan like so:

    mpv/build/mpv --no-config --gpu-debug --log-file=output.txt ~/Movies/big_buck_bunny_1080p_h264.mov

  • Quit mpv

  • TSan reports the following error:

    SUMMARY: ThreadSanitizer: data race (mpv:arm64+0x1002bec30) in unref_image+0x6c

Expected Behavior

TSan does not detect any data races.

Actual Behavior

For some videos, TSan reports a data race in unref_image when mpv is quitting. Full console output below.

Console output with TSan errors:
low-batt@gag mpv-build (master %=)$ mpv/build/mpv --no-config --gpu-debug --log-file=output.txt ~/Movies/big_buck_bunny_1080p_h264.mov 
[lavf] Failed to convert channel layout 6 channels (FC+FL+FR+SL+SR+LFE) to mpv one!
● Video  --vid=1  --vlang=eng  (h264 1920x1080 24 fps 9283 kbps) [default]
● Audio  --aid=1  --alang=eng  (aac 48000 Hz 438 kbps) [default]
AO: [coreaudio] 48000Hz fr-fl (stereo) 2ch floatp
VO: [gpu-next] 1920x1080 yuv420p
AV: 00:00:04 / 00:09:56 (1%) A-V:  0.000 Dropped: 1==================
WARNING: ThreadSanitizer: data race (pid=25838)
  Read of size 1 at 0x000111675d70 by thread T4 (mutexes: write M0):
    #0 unref_image <null> (mpv:arm64+0x1002bec30)
    #1 av_buffer_unref <null> (mpv:arm64+0x100d08cf0)
    #2 flush_all <null> (mpv:arm64+0x10029ce84)
    #3 uninit_avctx <null> (mpv:arm64+0x10029cb38)
    #4 vd_lavc_destroy <null> (mpv:arm64+0x10029c9c4)
    #5 filter_destructor <null> (mpv:arm64+0x10018c92c)
    #6 ta_free <null> (mpv:arm64+0x100341f00)
    #7 decf_destroy <null> (mpv:arm64+0x10016c420)
    #8 filter_destructor <null> (mpv:arm64+0x10018c92c)
    #9 ta_free <null> (mpv:arm64+0x100341f00)
    #10 mp_filter_free_children <null> (mpv:arm64+0x10018bf24)
    #11 public_f_destroy <null> (mpv:arm64+0x10016c2c8)
    #12 filter_destructor <null> (mpv:arm64+0x10018c92c)
    #13 ta_free <null> (mpv:arm64+0x100341f00)
    #14 vo_chain_uninit <null> (mpv:arm64+0x100256b10)
    #15 uninit_video_chain <null> (mpv:arm64+0x1002568e8)
    #16 play_current_file <null> (mpv:arm64+0x100237db8)
    #17 mp_play_files <null> (mpv:arm64+0x100235724)
    #18 mpv_main <null> (mpv:arm64+0x10023e824)
    #19 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Previous write of size 1 at 0x000111675d70 by thread T27 (mutexes: write M1, write M2, write M3):
    #0 mp_image_pool_get_no_alloc <null> (mpv:arm64+0x1002beb44)
    #1 get_buffer2_direct <null> (mpv:arm64+0x1002a18d8)
    #2 ff_get_buffer <null> (mpv:arm64+0x1005cd95c)

  Location is heap block of size 88 at 0x000111675d20 allocated by thread T26:
    #0 malloc <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x67d68)
    #1 ta_alloc_size <null> (mpv:arm64+0x1003418b0)
    #2 mp_image_pool_add <null> (mpv:arm64+0x1002bed14)
    #3 get_buffer2_direct <null> (mpv:arm64+0x1002a1a34)
    #4 ff_get_buffer <null> (mpv:arm64+0x1005cd95c)

  Mutex M0 (0x000101fc9050) created at:
    #0 pthread_mutex_lock <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x35a34)
    #1 mp_image_pool_get_no_alloc <null> (mpv:arm64+0x1002be6ac)
    #2 get_buffer2_direct <null> (mpv:arm64+0x1002a18d8)
    #3 ff_get_buffer <null> (mpv:arm64+0x1005cd95c)

  Mutex M1 (0x00011211d218) created at:
    #0 pthread_mutex_init <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x35664)
    #1 ff_pthread_init <null> (mpv:arm64+0x1013beacc)
    #2 reinit <null> (mpv:arm64+0x10029c8c0)
    #3 create <null> (mpv:arm64+0x10029b5c0)
    #4 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #5 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #6 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #7 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #8 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #9 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #10 play_current_file <null> (mpv:arm64+0x100237418)
    #11 mp_play_files <null> (mpv:arm64+0x100235724)
    #12 mpv_main <null> (mpv:arm64+0x10023e824)
    #13 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Mutex M2 (0x000111225698) created at:
    #0 pthread_mutex_init <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x35664)
    #1 ff_pthread_init <null> (mpv:arm64+0x1013beacc)
    #2 reinit <null> (mpv:arm64+0x10029c8c0)
    #3 create <null> (mpv:arm64+0x10029b5c0)
    #4 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #5 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #6 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #7 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #8 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #9 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #10 play_current_file <null> (mpv:arm64+0x100237418)
    #11 mp_play_files <null> (mpv:arm64+0x100235724)
    #12 mpv_main <null> (mpv:arm64+0x10023e824)
    #13 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Mutex M3 (0x000111032948) created at:
    #0 pthread_mutex_init <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x35664)
    #1 mp_mutex_init <null> (mpv:arm64+0x10029c74c)
    #2 create <null> (mpv:arm64+0x10029b4f0)
    #3 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #4 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #5 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #6 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #7 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #8 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #9 play_current_file <null> (mpv:arm64+0x100237418)
    #10 mp_play_files <null> (mpv:arm64+0x100235724)
    #11 mpv_main <null> (mpv:arm64+0x10023e824)
    #12 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Thread T4 (tid=6544855, running) created by main thread at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x33bac)
    #1 Application.main(_:_:) <null> (mpv:arm64+0x100017e8c)
    #2 main <null> (mpv:arm64+0x1003a0e90)

  Thread T27 (tid=6544930, running) created by thread T4 at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x33bac)
    #1 init_thread <null> (mpv:arm64+0x1013bf134)
    #2 reinit <null> (mpv:arm64+0x10029c8c0)
    #3 create <null> (mpv:arm64+0x10029b5c0)
    #4 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #5 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #6 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #7 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #8 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #9 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #10 play_current_file <null> (mpv:arm64+0x100237418)
    #11 mp_play_files <null> (mpv:arm64+0x100235724)
    #12 mpv_main <null> (mpv:arm64+0x10023e824)
    #13 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Thread T26 (tid=6544929, running) created by thread T4 at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x33bac)
    #1 init_thread <null> (mpv:arm64+0x1013bf134)
    #2 reinit <null> (mpv:arm64+0x10029c8c0)
    #3 create <null> (mpv:arm64+0x10029b5c0)
    #4 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #5 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #6 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #7 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #8 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #9 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #10 play_current_file <null> (mpv:arm64+0x100237418)
    #11 mp_play_files <null> (mpv:arm64+0x100235724)
    #12 mpv_main <null> (mpv:arm64+0x10023e824)
    #13 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

SUMMARY: ThreadSanitizer: data race (mpv:arm64+0x1002bec30) in unref_image+0x6c
==================

Exiting... (Quit)
ThreadSanitizer: reported 1 warnings
Abort trap: 6
low-batt@gag mpv-build (master %=)$ 
Log File

output.txt

Sample Files

I downloaded a H.264 encoded copy of Big Buck Bunny from here using this link to reproduce the problem.

The data race is not reproducible with all videos, but I have reproduced it with other videos.

I carefully read all instruction and confirm that I did the following:
  • I tested and confirmed that the issue exists with the latest release version or newer.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
Lingua principale
C
Stelle
38.2k
Fork
3.7k
Merge medio
1g 13h
PR unite (30g)
76

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di mpv-player/mpv

Tutte le issue di mpv-player/mpv

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.