Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 0541c23

Browse files
clopezjgraham
authored andcommitted
Retry the download of the webkitgtk nightly built product. (#19725)
* It has been observed that the download on taskcluster fails with a "socket.error: [Errno 104] Connection reset by peer" error. * This moves the download code to a new function that will retry the download in that case. Up to 3 times by default.
1 parent 98d32c4 commit 0541c23

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

tools/ci/run_tc.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import subprocess
4343
import sys
4444
import tempfile
45+
from socket import error as SocketError # NOQA: N812
46+
import errno
4547
try:
4648
from urllib2 import urlopen
4749
except ImportError:
@@ -161,15 +163,41 @@ def install_webkitgtk_from_apt_repository(channel):
161163
run(["sudo", "apt-get", "-qqy", "-t", "bionic-wpt-webkit-updates", "install", "webkit2gtk-driver"])
162164

163165

166+
# Download an URL in chunks and saves it to a file descriptor (truncating it)
167+
# It doesn't close the descriptor, but flushes it on success.
168+
# It retries the download in case of ECONNRESET up to max_retries.
169+
def download_url_to_descriptor(fd, url, max_retries=3):
170+
download_succeed = False
171+
if max_retries < 0:
172+
max_retries = 0
173+
for current_retry in range(max_retries+1):
174+
try:
175+
resp = urlopen(url)
176+
# We may come here in a retry, ensure to truncate fd before start writing.
177+
fd.seek(0)
178+
fd.truncate(0)
179+
while True:
180+
chunk = resp.read(16*1024)
181+
if not chunk:
182+
break # Download finished
183+
fd.write(chunk)
184+
fd.flush()
185+
download_succeed = True
186+
break # Sucess
187+
except SocketError as e:
188+
if e.errno != errno.ECONNRESET:
189+
raise # Unknown error
190+
if current_retry < max_retries:
191+
print("ERROR: Connection reset by peer. Retrying ...")
192+
continue # Retry
193+
return download_succeed
194+
195+
164196
def install_webkitgtk_from_tarball_bundle(channel):
165197
with tempfile.NamedTemporaryFile(suffix=".tar.xz") as temp_tarball:
166-
resp = urlopen("https://webkitgtk.org/built-products/nightly/webkitgtk-nightly-build-last.tar.xz")
167-
while True:
168-
chunk = resp.read(16*1024)
169-
if not chunk:
170-
break
171-
temp_tarball.write(chunk)
172-
temp_tarball.flush()
198+
download_url = "https://webkitgtk.org/built-products/nightly/webkitgtk-nightly-build-last.tar.xz"
199+
if not download_url_to_descriptor(temp_tarball, download_url):
200+
raise RuntimeError("Can't download %s. Aborting" % download_url)
173201
run(["sudo", "tar", "xfa", temp_tarball.name, "-C", "/"])
174202
# Install dependencies
175203
run(["sudo", "apt-get", "-qqy", "update"])

0 commit comments

Comments
 (0)