KubeSpawner is blocking new requests to the Hub

Hello,

I set a callable for the profile_list in the KubeSpawner.
This callable makes a request to another pod, which generates the list of profiles for the user in YAML format.
So far I had no problems with this, but now I need a new value in the YAML and have to make a request to the JupyterHub API.

I am trying to display the request history:
Browser → Ingress → Hub → KubeSpawner → Tool → Hub-Api

The problem that occurred is the following.
Due to the request from KubeSpawner.profile_list to the tool, the whole hub is apparently blocked. As a result, the request from the tool to the hub API does not get through. Only when a timeout occurs is everything unblocked again.

I’m wondering why KubeSpawner.profile_list runs via the main thread? I assumed that each request is handled in parallel by the browser so that they don’t block each other.
Or am I misunderstanding something fundamental?

Many thanks for your help.

async def get_profile_list(spawner):
    auth_state = await spawner.user.get_auth_state()

    ....

    profile_list = []
    response = requests.get(f"http://tool-service:5000/yaml", ...)
    profiles = response.json()["data"]
    for profile_str in profiles :
         profile = yaml.safe_load(profile_str)
         profile_list.append(profile[0])
    return profile_list

c.KubeSpawner.profile_list = get_profile_list

get_profile_list is called on the hub side not in the browser. It’s an async function, but

isn’t async, so it blocks. You’ll need to use an async alternative to requests, e.g. see
https://www.tornadoweb.org/en/stable/guide/async.html

1 Like