From be6ec28dab385c2d64e26131c89e7538c039ed1d Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Tue, 5 Oct 2021 02:30:52 +0530 Subject: [PATCH] Fail suspected API requests with 404, not 503 Non-running user servers making requests is a fairly common occurance - user servers get culled while their browser tabs are left open. So we now have a background level of 503s responses on the hub *all* the time, making it very difficult to detect *real* 503s, which should ideally be closely monitored and alerted on. I *think* 404 is a more appropriate response, as the resource (API) being requested is no longer present. --- jupyterhub/handlers/base.py | 2 +- jupyterhub/tests/test_pages.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index b0e926ec..024f4a9e 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -1349,7 +1349,7 @@ class UserUrlHandler(BaseHandler): self.log.warning( "Failing suspected API request to not-running server: %s", self.request.path ) - self.set_status(503) + self.set_status(404) self.set_header("Content-Type", "application/json") spawn_url = urlparse(self.request.full_url())._replace(query="") diff --git a/jupyterhub/tests/test_pages.py b/jupyterhub/tests/test_pages.py index 7140b823..133aa426 100644 --- a/jupyterhub/tests/test_pages.py +++ b/jupyterhub/tests/test_pages.py @@ -1001,7 +1001,7 @@ async def test_token_page(app): async def test_server_not_running_api_request(app): cookies = await app.login_user("bees") r = await get_page("user/bees/api/status", app, hub=False, cookies=cookies) - assert r.status_code == 503 + assert r.status_code == 404 assert r.headers["content-type"] == "application/json" message = r.json()['message'] assert ujoin(app.base_url, "hub/spawn/bees") in message