TSan detected data race in unref_image
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 47/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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_optionsfile 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
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.
- Dominant language
- C
- Stars
- 38.2k
- Forks
- 3.7k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 76
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mpv-player/mpv
-
meta:feature-request
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
mpv-player/mpv#18855 · 2 comments ·
Maintainers usually reply within 1 day
-
meta:feature-request
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
mpv-player/mpv#18683 · 4 comments ·
Maintainers usually reply within 1 day
-
Subtitle delay value displays "-0ms"May be free again A pull request for this issue was closed without being merged. Openos:linux
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
mpv-player/mpv#18649 · 1 comment ·
Maintainers usually reply within 1 day
-
meta:feature-request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mpv-player/mpv#18464 ·
Maintainers usually reply within 1 day
-
Keyboard shortcut next and previous secondary subtitle filePossibly taken @ravarnax claimed this 225 days ago. Openmeta:feature-request
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mpv-player/mpv#17693 · 5 comments · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
`sha256()` returns a wrong hash when libsql-ffi is built with gcc 11 or laterPossibly taken @colinhacks claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tursodatabase/libsql#2333 ·
Maintainers usually reply within 11 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
OpenPrinting/cups#1826 ·
Maintainers usually reply within 1 day
-
Backport to 3.0 advertises a suffix that does not existPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
389ds/389-ds-base#8152 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RetroAchievements/rcheevos#580 · 1 comment ·
Maintainers usually reply within 5 days