From 7c245d08687218707fa1e010d7abc1afeba13d09 Mon Sep 17 00:00:00 2001 From: Romain Primet Date: Fri, 13 Jul 2018 15:36:44 +0200 Subject: [PATCH 1/4] remove hard-coded constant from retry loop --- tljh/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tljh/installer.py b/tljh/installer.py index 1152867..4dd94fd 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -139,7 +139,7 @@ def ensure_jupyterhub_running(times=4): Loops given number of times, waiting a second each. """ - for i in range(4): + for i in range(times): try: print('Waiting for JupyterHub to come up ({}/{} tries)'.format(i + 1, times)) urlopen('http://127.0.0.1') From baef6d0bd9490d0f1ddbacf8bea129e10c998479 Mon Sep 17 00:00:00 2001 From: Romain Primet Date: Fri, 13 Jul 2018 15:55:41 +0200 Subject: [PATCH 2/4] handle transient 404 --- tljh/installer.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tljh/installer.py b/tljh/installer.py index 4dd94fd..0ceb417 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -2,6 +2,7 @@ import sys import os import tljh.systemd as systemd import tljh.conda as conda +from urllib.error import HTTPError from urllib.request import urlopen, URLError from tljh import user import secrets @@ -151,6 +152,13 @@ def ensure_jupyterhub_running(times=4): continue # Everything else should immediately abort raise + except HTTPError as h: + if h.code == 404: + # May be transient + time.sleep(1) + continue + # Everything else should immediately abort + raise raise Exception("Installation failed: JupyterHub did not start in {}s".format(times)) From c24b536bd954fe1263004e58302c3a84df6cfb2c Mon Sep 17 00:00:00 2001 From: Romain Primet Date: Fri, 13 Jul 2018 16:29:30 +0200 Subject: [PATCH 3/4] handle 503 as well --- tljh/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tljh/installer.py b/tljh/installer.py index 0ceb417..51205e3 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -153,7 +153,7 @@ def ensure_jupyterhub_running(times=4): # Everything else should immediately abort raise except HTTPError as h: - if h.code == 404: + if h.code in [404, 503]: # May be transient time.sleep(1) continue From 61a7f80df2095b376196af67f66380414eec3a3c Mon Sep 17 00:00:00 2001 From: Romain Primet Date: Fri, 13 Jul 2018 14:56:00 +0000 Subject: [PATCH 4/4] handle 404 and 503 transient errors --- tljh/installer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tljh/installer.py b/tljh/installer.py index 51205e3..611f3c7 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -145,16 +145,16 @@ def ensure_jupyterhub_running(times=4): print('Waiting for JupyterHub to come up ({}/{} tries)'.format(i + 1, times)) urlopen('http://127.0.0.1') return - except URLError as e: - if isinstance(e.reason, ConnectionRefusedError): - # Hub isn't up yet, sleep & loop + except HTTPError as h: + if h.code in [404, 503]: + # May be transient time.sleep(1) continue # Everything else should immediately abort raise - except HTTPError as h: - if h.code in [404, 503]: - # May be transient + except URLError as e: + if isinstance(e.reason, ConnectionRefusedError): + # Hub isn't up yet, sleep & loop time.sleep(1) continue # Everything else should immediately abort