From: Derek Buitenhuis <derek.buitenhuis@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 7/9] avformat/http: Add option to limit total reconnect delay Date: Mon, 22 Apr 2024 15:25:45 +0100 Message-ID: <20240422142547.281064-8-derek.buitenhuis@gmail.com> (raw) In-Reply-To: <20240422142547.281064-1-derek.buitenhuis@gmail.com> The existing option only allows users to set the max delay for a single attempt, rather than the total allowed delay, which is both pretty unintitive, and only applicable when exponential backoff is used. The default for this option is set to 256, which is just above the effective total delay accomplished by the the existing reconnect_delay_max default of 120. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> --- libavformat/http.c | 12 ++++++++++-- libavformat/version.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 06bd3e340e..930c115ec3 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -141,6 +141,7 @@ typedef struct HTTPContext { int respect_retry_after; unsigned int retry_after; int reconnect_max_retries; + int reconnect_delay_total_max; } HTTPContext; #define OFFSET(x) offsetof(HTTPContext, x) @@ -180,6 +181,7 @@ static const AVOption options[] = { { "reconnect_streamed", "auto reconnect streamed / non seekable streams", OFFSET(reconnect_streamed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D }, { "reconnect_delay_max", "max reconnect delay in seconds after which to give up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, UINT_MAX/1000/1000, D }, { "reconnect_max_retries", "the max number of times to retry a connection", OFFSET(reconnect_max_retries), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, D }, + { "reconnect_delay_total_max", "max total reconnect delay in seconds after which to give up", OFFSET(reconnect_delay_total_max), AV_OPT_TYPE_INT, { .i64 = 256 }, 0, UINT_MAX/1000/1000, D }, { "respect_retry_after", "respect the Retry-After header when retrying connections", OFFSET(respect_retry_after), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, D }, { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, D | E }, { "resource", "The resource requested by a client", OFFSET(resource), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E }, @@ -363,6 +365,7 @@ static int http_open_cnx(URLContext *h, AVDictionary **options) HTTPContext *s = h->priv_data; int ret, conn_attempts = 1, auth_attempts = 0, redirects = 0; int reconnect_delay = 0; + int reconnect_delay_total = 0; uint64_t off; char *cached; @@ -389,7 +392,8 @@ redo: if (ret < 0) { if (!http_should_reconnect(s, ret) || reconnect_delay > s->reconnect_delay_max || - (s->reconnect_max_retries >= 0 && conn_attempts > s->reconnect_max_retries)) + (s->reconnect_max_retries >= 0 && conn_attempts > s->reconnect_max_retries) || + reconnect_delay_total > s->reconnect_delay_total_max) goto fail; if (s->respect_retry_after && s->retry_after > 0) { @@ -403,6 +407,7 @@ redo: ret = ff_network_sleep_interruptible(1000U * 1000 * reconnect_delay, &h->interrupt_callback); if (ret != AVERROR(ETIMEDOUT)) goto fail; + reconnect_delay_total += reconnect_delay; reconnect_delay = 1 + 2 * reconnect_delay; conn_attempts++; @@ -1710,6 +1715,7 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size) int err, read_ret; int64_t seek_ret; int reconnect_delay = 0; + int reconnect_delay_total = 0; int conn_attempt = 1; if (!s->hd) @@ -1739,13 +1745,15 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size) !(s->reconnect_at_eof && read_ret == AVERROR_EOF)) break; - if (reconnect_delay > s->reconnect_delay_max || (s->reconnect_max_retries >= 0 && conn_attempt > s->reconnect_max_retries)) + if (reconnect_delay > s->reconnect_delay_max || (s->reconnect_max_retries >= 0 && conn_attempt > s->reconnect_max_retries) || + reconnect_delay_total > s->reconnect_delay_total_max) return AVERROR(EIO); av_log(h, AV_LOG_WARNING, "Will reconnect at %"PRIu64" in %d second(s), error=%s.\n", s->off, reconnect_delay, av_err2str(read_ret)); err = ff_network_sleep_interruptible(1000U*1000*reconnect_delay, &h->interrupt_callback); if (err != AVERROR(ETIMEDOUT)) return err; + reconnect_delay_total += reconnect_delay; reconnect_delay = 1 + 2*reconnect_delay; conn_attempt++; seek_ret = http_seek_internal(h, target, SEEK_SET, 1); diff --git a/libavformat/version.h b/libavformat/version.h index 41dbd4ad01..5310326bda 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" #define LIBAVFORMAT_VERSION_MINOR 3 -#define LIBAVFORMAT_VERSION_MICRO 102 +#define LIBAVFORMAT_VERSION_MICRO 103 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-04-22 14:27 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-22 14:25 [FFmpeg-devel] [PATCH v2 0/9] HTTP rate limiting and retry improvements Derek Buitenhuis 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 1/9] avutil/error: Add HTTP 429 Too Many Requests AVERROR code Derek Buitenhuis 2024-04-22 15:20 ` Derek Buitenhuis 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 2/9] avformat/http: Use AVERROR_HTTP_TOO_MANY_REQUESTS Derek Buitenhuis 2024-04-24 10:53 ` Martin Storsjö 2024-04-24 19:40 ` Derek Buitenhuis 2024-04-24 10:58 ` Martin Storsjö 2024-04-24 19:41 ` Derek Buitenhuis 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 3/9] avformat/http: Don't bail on parsing headers on "bad" HTTP codes Derek Buitenhuis 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 4/9] avformat/http: Add support for Retry-After header Derek Buitenhuis 2024-04-24 11:06 ` Martin Storsjö 2024-04-24 19:40 ` Derek Buitenhuis 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 5/9] avformat/http: Rename attempts to auth_attempts Derek Buitenhuis 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 6/9] avformat/http: Add options to set the max number of connection retries Derek Buitenhuis 2024-04-24 11:08 ` Martin Storsjö 2024-04-24 19:42 ` Derek Buitenhuis 2024-04-22 14:25 ` Derek Buitenhuis [this message] 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 8/9] doc/protocols: Re-order HTTP options to match http.c order Derek Buitenhuis 2024-04-22 14:25 ` [FFmpeg-devel] [PATCH v2 9/9] doc/protocols: Fill in missing HTTP options Derek Buitenhuis 2024-04-24 11:13 ` [FFmpeg-devel] [PATCH v2 0/9] HTTP rate limiting and retry improvements Martin Storsjö 2024-04-24 19:43 ` Derek Buitenhuis 2024-04-25 13:27 ` Derek Buitenhuis
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240422142547.281064-8-derek.buitenhuis@gmail.com \ --to=derek.buitenhuis@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git