From 9a3d58183dcd3c8a4bfad43520aedf341ff62d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 1 Oct 2026 01:15:57 +0200 Subject: [PATCH] avformat/libcurl: take the open result from the first reply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decide whether the open succeeded from the first reply only, so that a follow-up request that the loop thread has already started cannot fail the open after the first reply turned out usable. Signed-off-by: Kacper Michajłow --- libavformat/libcurl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavformat/libcurl.c b/libavformat/libcurl.c index 80c1f7a9fa..23d7f5f751 100644 --- a/libavformat/libcurl.c +++ b/libavformat/libcurl.c @@ -174,6 +174,7 @@ struct CurlContext { /* Probe result. Set by the loop thread, read by url_open() once probed. */ int probed; + int probe_ok; /* the first reply can be read */ int stream_ok; int seekable; int64_t content_size; @@ -626,7 +627,10 @@ static size_t header_callback(char *ptr, size_t size, size_t nitems, void *userd c->stream_ok = 0; update_status_locked(c, ff_http_averror(status, AVERROR(EIO)), CURLE_OK); } - c->probed = 1; + if (!c->probed) { + c->probe_ok = c->stream_ok; + c->probed = 1; + } pthread_cond_broadcast(&c->cond); pthread_mutex_unlock(&c->mutex); @@ -1349,7 +1353,7 @@ static int wait_for_probe(CurlContext *c) curl_cond_wait(c); } if (!ret) { - if (!c->stream_ok) + if (!c->probe_ok) ret = c->status ? c->status : AVERROR(EIO); } pthread_mutex_unlock(&c->mutex);