This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 9140cbe583df1464ccd000bd720f8a69c4d98d69
Author:     Niklas Haas <[email protected]>
AuthorDate: Wed Jun 10 14:00:20 2026 +0200
Commit:     Niklas Haas <[email protected]>
CommitDate: Sun Jun 14 11:10:12 2026 +0200

    avformat/shared: don't read directly into cache file when racing writes
    
    Instead, read to the output/temporary buffer (write_back path). This is to
    lessen the impact of racing the write against other clients trying to race
    the same pending block.
    
    Sponsored-by: nxtedition AB
    Signed-off-by: Niklas Haas <[email protected]>
---
 libavformat/shared.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavformat/shared.c b/libavformat/shared.c
index 1030613479..136bd7af27 100644
--- a/libavformat/shared.c
+++ b/libavformat/shared.c
@@ -600,7 +600,7 @@ static int shared_read(URLContext *h, unsigned char *buf, 
int size)
     Block *const block = &s->spacemap->blocks[block_id];
     unsigned short state = atomic_load_explicit(&block->state, 
memory_order_acquire);
     int64_t pending_since = 0;
-    int verify_read = 0;
+    int verify_read = 0, is_race = 0;
 
 retry:
     switch (state) {
@@ -661,11 +661,14 @@ retry:
     case BLOCK_PENDING:
         /* Another thread is busy fetching this block, wait for it to finish */
         if (!s->timeout) {
+            is_race = 1;
             break; /* no timeout requested, immediately race to fetch block */
         } else if (pending_since) {
             int64_t new = av_gettime_relative();
-            if (new - pending_since >= s->timeout)
+            if (new - pending_since >= s->timeout) {
+                is_race = 1;
                 break; /* timeout expired, try to fetch the block ourselves */
+            }
         } else {
             pending_since = av_gettime_relative();
         }
@@ -720,7 +723,7 @@ retry:
     }
 
     int write_back = 1;
-    if (s->cache_data) {
+    if (s->cache_data && !is_race) {
         /* Read directly into memory mapped cache file */
         tmp = s->cache_data + block_pos;
         write_back = 0;

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to