diff --git a/gns3server/handlers/api/version_handler.py b/gns3server/handlers/api/version_handler.py index af01fe14..930c733e 100644 --- a/gns3server/handlers/api/version_handler.py +++ b/gns3server/handlers/api/version_handler.py @@ -47,12 +47,3 @@ class VersionHandler: if request.json["version"] != __version__: raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"], __version__)) response.json({"version": __version__}) - - @staticmethod - @Route.get( - r"/sleep/{vm_id}", - description="Retrieve the server version number", - output=VERSION_SCHEMA) - def sleep(request, response): - yield from asyncio.sleep(1) - response.json({"version": __version__}) diff --git a/gns3server/web/route.py b/gns3server/web/route.py index 8afaae20..bf30e35f 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -163,9 +163,16 @@ class Route(object): vm_id = request.match_info.get("vm_id") if vm_id is None: vm_id = request.match_info["device_id"] - cls._vm_locks.setdefault(vm_id, asyncio.Lock()) - with (yield from cls._vm_locks[vm_id]): + cls._vm_locks.setdefault(vm_id, {"lock": asyncio.Lock(), "concurrency": 0}) + cls._vm_locks[vm_id]["concurrency"] += 1 + + with (yield from cls._vm_locks[vm_id]["lock"]): response = yield from control_schema(request) + cls._vm_locks[vm_id]["concurrency"] -= 1 + + # No more waiting requests, garbage collect the lock + if cls._vm_locks[vm_id]["concurrency"] <= 0: + del cls._vm_locks[vm_id] else: response = yield from control_schema(request) return response