From 536e435c06ddba628c85369c73d9683cdb8ac802 Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Sun, 19 May 2019 22:29:18 -0700 Subject: [PATCH] Retry downloading traefik if it fails Fixes #314 --- setup.py | 1 + tljh/traefik.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 61f8ead..4597a95 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ setup( 'jinja2', 'pluggy>0.7<1.0', 'passlib', + 'backoff', 'jupyterhub-traefik-proxy==0.1.*' ], entry_points={ diff --git a/tljh/traefik.py b/tljh/traefik.py index 4581953..4e05b7a 100644 --- a/tljh/traefik.py +++ b/tljh/traefik.py @@ -1,10 +1,11 @@ """Traefik installation and setup""" import hashlib import os -from urllib.request import urlretrieve +from urllib.request import urlretrieve, ContentTooShortError from jinja2 import Template from passlib.apache import HtpasswdFile +import backoff from tljh.configurer import load_config @@ -26,7 +27,12 @@ def checksum_file(path): hasher.update(chunk) return hasher.hexdigest() - +@backoff.on_exception( + backoff.expo, + # Retry when connection is reset or we think we didn't download entire file + (ConnectionResetError, ContentTooShortError), + max_tries=2 +) def ensure_traefik_binary(prefix): """Download and install the traefik binary""" traefik_bin = os.path.join(prefix, "bin", "traefik")