From 2841b5769ee9f43689086a2023c6e8a79a442eac Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 14 Apr 2016 12:15:45 +0200 Subject: [PATCH] Lock for controller or compute --- gns3server/web/route.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gns3server/web/route.py b/gns3server/web/route.py index 6b7673d8..f7bb8036 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -242,16 +242,23 @@ 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, {"lock": asyncio.Lock(), "concurrency": 0}) - cls._vm_locks[vm_id]["concurrency"] += 1 - with (yield from cls._vm_locks[vm_id]["lock"]): + if "controller" in request.path: + type = "controller" + else: + type = "compute" + lock_key = "{}:{}:{}".format(type, request.match_info["project_id"], vm_id) + + cls._vm_locks.setdefault(lock_key, {"lock": asyncio.Lock(), "concurrency": 0}) + cls._vm_locks[lock_key]["concurrency"] += 1 + + with (yield from cls._vm_locks[lock_key]["lock"]): response = yield from control_schema(request) - cls._vm_locks[vm_id]["concurrency"] -= 1 + cls._vm_locks[lock_key]["concurrency"] -= 1 # No more waiting requests, garbage collect the lock - if cls._vm_locks[vm_id]["concurrency"] <= 0: - del cls._vm_locks[vm_id] + if cls._vm_locks[lock_key]["concurrency"] <= 0: + del cls._vm_locks[lock_key] else: response = yield from control_schema(request) return response