mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-11 20:13:02 +00:00
add lock to prevent concurrent calls to check_routes
This commit is contained in:
@@ -19,6 +19,7 @@ Route Specification:
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from functools import wraps
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
@@ -41,6 +42,21 @@ from . import utils
|
|||||||
from .utils import url_path_join
|
from .utils import url_path_join
|
||||||
|
|
||||||
|
|
||||||
|
def _one_at_a_time(method):
|
||||||
|
"""decorator to limit an async method to be called only once
|
||||||
|
|
||||||
|
If multiple concurrent calls to this method are made,
|
||||||
|
queue them instead of allowing them to be concurrently outstanding.
|
||||||
|
"""
|
||||||
|
method._lock = asyncio.Lock()
|
||||||
|
@wraps(method)
|
||||||
|
async def locked_method(*args, **kwargs):
|
||||||
|
async with method._lock:
|
||||||
|
return await method(*args, **kwargs)
|
||||||
|
|
||||||
|
return locked_method
|
||||||
|
|
||||||
|
|
||||||
class Proxy(LoggingConfigurable):
|
class Proxy(LoggingConfigurable):
|
||||||
"""Base class for configurable proxies that JupyterHub can use.
|
"""Base class for configurable proxies that JupyterHub can use.
|
||||||
|
|
||||||
@@ -271,6 +287,7 @@ class Proxy(LoggingConfigurable):
|
|||||||
# wait after submitting them all
|
# wait after submitting them all
|
||||||
await gen.multi(futures)
|
await gen.multi(futures)
|
||||||
|
|
||||||
|
@_one_at_a_time
|
||||||
async def check_routes(self, user_dict, service_dict, routes=None):
|
async def check_routes(self, user_dict, service_dict, routes=None):
|
||||||
"""Check that all users are properly routed on the proxy."""
|
"""Check that all users are properly routed on the proxy."""
|
||||||
if not routes:
|
if not routes:
|
||||||
|
Reference in New Issue
Block a user