diff --git a/libavformat/avio.c b/libavformat/avio.c
index 4ab1b6bd75a7dca1986369be5cbeb8a8e7d6053e..2265549266e02ebba7d3fd0f5962c50664b3e937 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -221,8 +221,6 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
 
     len = 0;
     while (len < size_min) {
-        if (url_interrupt_cb())
-            return AVERROR(EINTR);
         ret = transfer_func(h, buf+len, size-len);
         if (ret == AVERROR(EINTR))
             continue;
@@ -239,6 +237,8 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
         if (ret)
            fast_retries = FFMAX(fast_retries, 2);
         len += ret;
+        if (url_interrupt_cb())
+            return AVERROR(EINTR);
     }
     return len;
 }