From patchwork Tue Sep 18 08:48:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artjom Vejsel X-Patchwork-Id: 10357 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp4438820jap; Tue, 18 Sep 2018 01:52:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYZqFOxDxJM9kIFHFPKNZWgJquZnrcDXjXM4wWCwMAbvD5mj0aLszjKNKi2uS9RYW8GbSdM X-Received: by 2002:adf:9ae5:: with SMTP id a92-v6mr23660030wrc.125.1537260763225; Tue, 18 Sep 2018 01:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537260763; cv=none; d=google.com; s=arc-20160816; b=Dc9vTwYfzdDU7ee0uQFw2sqFaQJWxzBzWbMigEREFGraimLHvW9Pf731L7JgxtfG/R EisBMJ4fURzXoLCpMHyeYOw/rSgk9/Kdm+MIZH/QItVp+e4TFDg1PASdMmoNtFjbmTef THbGK+HP1/qxbrSI7SoVmrb76MlDZAtX0LBeJwAANLj+MTbcR7dURYlZR0QMNr4IYE2l 8Gdqyg9AJjTSJAjB6ULEGwski9eC6bUwR8yLGsShO2BdQLX49uAZm7CJxTiFStPmk1O2 s90i8OxzpN8GH+Gz7pfNkWRYZFyq4SKub9Yv07zhu8mPpO+M/A3aT8iz38w1HZ5oh7+b XC3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=WvJI9X9PHB3Jmj4mdfqYTKsLw1cxMuqmEDm6AVXU/bE=; b=FL6+8cq3LAJdjTWRkxzN3zqawNvXYtRGRefL7ojTRbc0uFV2P9uS1si/iLYo9iz5sY nZJFYqZp2HhiIh21H9WcRGGSDodQ+TzSL7BiblZ/lCZqNccIcWpoB4qyJ8zLP+zq1N5K T9W3nut32LRd+Qlde/rx1raNJGhLO8VNzT9iLMvIIeZEM5uFRrwSLvneVwVLsYggfNxJ oQuiy8X0V1+bTxbb/0ttozNDKb0rNjIhTl6HklPn6YL9PKTNJ1suxb+5cUd9J9SpvUw0 6N6KhJBea/q9+WkMbRwGSX4rSFvJQFiV3b6Pzkc5nO0SZiiX3h3lSF1UhGrZyWIW9VgG VtZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=RWkUOGTV; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 64-v6si9415883wma.162.2018.09.18.01.52.42; Tue, 18 Sep 2018 01:52:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=RWkUOGTV; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F2ED668A517; Tue, 18 Sep 2018 11:52:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 96FC368A427 for ; Tue, 18 Sep 2018 11:52:21 +0300 (EEST) Received: by mail-lj1-f193.google.com with SMTP id v9-v6so1021992ljk.4 for ; Tue, 18 Sep 2018 01:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XL1rYJIHeK/9RB6bxxiZVZfEqCx8B5i+YHUGqPshJYU=; b=RWkUOGTVOQgCKXtam23r5l+ph6LwQpzLXZ0o/4wtVFiK/9CNlG80DJtzCk0qKDBqoM N3Ei6vHrB8sw0jYC6DoIQxs2cxBJAbPGNoxuf2I+VpjL0qvwIgwTFhbK/RGxaC+QSzyS k0oQhJAQlyqpXmm+wYf3St50OC1rHdxUubO+TajATrlk9xMZKQ/oavuZkms9yiJz7Jbb qWiZAKobJjpmlHrWGhEOvlBZbSALYW6mpZ8iMoN59pq0kIjxIco5T92eGxizU1I6qUk7 kCblZlJmUmNry9TmOX2w0LsyopWTAoocTJtJoPni8B33uF9YeO52mTBe+0ILrcUGimDa 0PuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XL1rYJIHeK/9RB6bxxiZVZfEqCx8B5i+YHUGqPshJYU=; b=qPAqnJyxJhMwMRv/ojP428KWl5lIg3pSll6Bz/apE9KBqa5TfVIO6govusMtgDbBEV Uz8Xu/oa7xU9UrWKx5VRfTFzYRLM32F2n5C+lDLysIjQR8tZ9OgZcJQLcyZG9kb17LOx 19hODvNqRVk2tIqFQKOhmKdrtpPm56+NJLurhVnJ18edi84JW7QkjWOF7MNRcH570Itm CIIbCyYjHGDBLjygRTp5vKGsMcccm7pIMQW7xebpWmQHOBlw8ZjVetmVpwGD/yzZDm1p dl/GmT2sI3CViUkHrZRwaOoWLAjP0s2QNo18DhYKZqQcf0T9x6SOnMiVAm3iYpqoXbAr IhLg== X-Gm-Message-State: APzg51BYm9mbEynuEFtgNXJCQrYvNIFPVTB9mPwj9QUVa8DfbDXmTKts P5FI1GvAnDtXFc+QPqlVO+r0NB0APEg= X-Received: by 2002:a2e:8957:: with SMTP id b23-v6mr19179502ljk.50.1537260753595; Tue, 18 Sep 2018 01:52:33 -0700 (PDT) Received: from localhost.localdomain (restream.net.dfw.ru. [185.41.113.130]) by smtp.gmail.com with ESMTPSA id m22-v6sm322732lfc.44.2018.09.18.01.52.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 01:52:32 -0700 (PDT) From: Artjom Vejsel To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Sep 2018 11:48:36 +0300 Message-Id: <20180918084836.27998-1-akawolf0@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH v2] http connect: retry few times before reporting about error X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Artjom Vejsel MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Artjom Vejsel --- libavformat/http.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 4fdb2f13f2..d3558f522e 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -252,7 +252,7 @@ static int http_open_cnx(URLContext *h, AVDictionary **options) { HTTPAuthType cur_auth_type, cur_proxy_auth_type; HTTPContext *s = h->priv_data; - int location_changed, attempts = 0, redirects = 0; + int location_changed, auth_attempts = 0, open_attempts = 1, redirects = 0; redo: av_dict_copy(options, s->chained_options, 0); @@ -260,13 +260,21 @@ redo: cur_proxy_auth_type = s->auth_state.auth_type; location_changed = http_open_cnx_internal(h, options); - if (location_changed < 0) - goto fail; + if (location_changed < 0) { + if (open_attempts < 4) { + av_log(h, AV_LOG_WARNING, "Couldn't get HTTP resource, retrying...\n"); + if (s->hd) + ffurl_closep(&s->hd); + open_attempts++; + goto redo; + } else + goto fail; + } - attempts++; + auth_attempts++; if (s->http_code == 401) { if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) && - s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) { + s->auth_state.auth_type != HTTP_AUTH_NONE && auth_attempts < 4) { ffurl_closep(&s->hd); goto redo; } else @@ -274,7 +282,7 @@ redo: } if (s->http_code == 407) { if ((cur_proxy_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) && - s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) { + s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && auth_attempts < 4) { ffurl_closep(&s->hd); goto redo; } else @@ -290,7 +298,7 @@ redo: /* Restart the authentication process with the new target, which * might use a different auth mechanism. */ memset(&s->auth_state, 0, sizeof(s->auth_state)); - attempts = 0; + auth_attempts = 0; location_changed = 0; goto redo; }