# Buggy code
async def finish_user_spawn():
    """Finish the user spawn by registering listeners and notifying the proxy.

    If the spawner is slow to start, this is passed as an async callback,
    otherwise it is called immediately.
    """
    # wait for spawn Future
    await spawn_future
    toc = IOLoop.current().time()
    self.log.info("User %s took %.3f seconds to start", user_server_name, toc - tic)
    self.statsd.timing("spawner.success", (toc - tic) * 1000)
    SERVER_SPAWN_DURATION_SECONDS.labels(status=ServerSpawnStatus.success).observe(
        time.perf_counter() - spawn_start_time
    )
    self.eventlog.record_event(
        "hub.jupyter.org/server-action",
        1,
        {"action": "start", "username": user.name, "servername": server_name},
    )
    proxy_add_start_time = time.perf_counter()
    spawner._proxy_pending = True
    try:
        await self.proxy.add_user(user, server_name)

        PROXY_ADD_DURATION_SECONDS.labels(status="success").observe(
            time.perf_counter() - proxy_add_start_time
        )
        RUNNING_SERVERS.inc()
    except Exception:
        self.log.exception("Failed to add %s to proxy!", user_server_name)
        self.log.error("Stopping %s to avoid inconsistent state", user_server_name)
        await user.stop()
        PROXY_ADD_DURATION_SECONDS.labels(status="failure").observe(
            time.perf_counter() - proxy_add_start_time
        )
    else:
        spawner.add_poll_callback(self.user_stopped, user, server_name)
    finally:
        spawner._proxy_pending = False


# Traceback (TimeoutError)
[E 2020-05-28 22:02:11.206 JupyterHub base:876] Failed to add michaeldzamba:doublegpu7 to proxy!
Traceback (most recent call last):
File "/fn/lib/python3.7/site-packages/jupyterhub/handlers/base.py", line 869, in finish_user_spawn
await self.proxy.add_user(user, server_name)
File "/fn/lib/python3.7/site-packages/jupyterhub/proxy.py", line 274, in add_user
{'user': user.name, 'server_name': server_name},
File "/fn/lib/python3.7/site-packages/jupyterhub_traefik_proxy/kv_proxy.py", line 289, in add_route
await self._wait_for_route(routespec, provider=self.kv_name)
File "/fn/lib/python3.7/site-packages/jupyterhub_traefik_proxy/proxy.py", line 147, in _wait_for_route
timeout=self.check_route_timeout,
File "/fn/lib/python3.7/site-packages/jupyterhub/utils.py", line 177, in exponential_backoff
raise TimeoutError(fail_message)
TimeoutError: Traefik route for /user/michaeldzamba/doublegpu7/ configuration not available
[E 2020-05-28 22:02:11.207 JupyterHub base:878] Stopping michaeldzamba:doublegpu7 to avoid inconsistent state
[I 2020-05-28 22:02:11.208 JupyterHub spawner:1866] Deleting pod jupyter-michaeldzamba

# Fixed code
async def finish_user_spawn():
    """Finish the user spawn by registering listeners and notifying the proxy.

    If the spawner is slow to start, this is passed as an async callback,
    otherwise it is called immediately.
    """
    # wait for spawn Future
    await spawn_future
    toc = IOLoop.current().time()
    self.log.info("User %s took %.3f seconds to start", user_server_name, toc - tic)
    self.statsd.timing("spawner.success", (toc - tic) * 1000)
    SERVER_SPAWN_DURATION_SECONDS.labels(status=ServerSpawnStatus.success).observe(
        time.perf_counter() - spawn_start_time
    )
    self.eventlog.record_event(
        "hub.jupyter.org/server-action",
        1,
        {"action": "start", "username": user.name, "servername": server_name},
    )
    proxy_add_start_time = time.perf_counter()
    spawner._proxy_pending = True
    try:
        await self.proxy.add_user(user, server_name)

        PROXY_ADD_DURATION_SECONDS.labels(status="success").observe(
            time.perf_counter() - proxy_add_start_time
        )
        RUNNING_SERVERS.inc()
    except Exception:
        self.log.exception("Failed to add %s to proxy!", user_server_name)
        self.log.error("Stopping %s to avoid inconsistent state", user_server_name)
        await user.stop(server_name)
        PROXY_ADD_DURATION_SECONDS.labels(status="failure").observe(
            time.perf_counter() - proxy_add_start_time
        )
    else:
        spawner.add_poll_callback(self.user_stopped, user, server_name)
    finally:
        spawner._proxy_pending = False