From 45b20d8374eddc3457b3c6c0fe003297a4ca072f Mon Sep 17 00:00:00 2001 From: Thomas HERVE Date: Tue, 28 May 2024 16:15:43 +0200 Subject: [PATCH] Add lock on release --- core/app/handlers/core.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/app/handlers/core.py b/core/app/handlers/core.py index 1b6e448..e23fe50 100644 --- a/core/app/handlers/core.py +++ b/core/app/handlers/core.py @@ -131,12 +131,16 @@ def delete_room(body): v1.delete_namespaced_service(namespace=namespace, name='instance-'+body["instance"]) # Remove ingress entry - networking = client.NetworkingV1Api() - current_ingress = networking.read_namespaced_ingress(name=ingress, namespace=namespace) - current_ingress_paths = current_ingress.spec.rules[0].http.paths - current_ingress_paths = list(filter(lambda x: x.backend.service.name != f"instance-{body['instance']}", current_ingress_paths)) - current_ingress.spec.rules[0].http.paths = current_ingress_paths + if lock.acquire_lock(): + try: + networking = client.NetworkingV1Api() + current_ingress = networking.read_namespaced_ingress(name=ingress, namespace=namespace) + current_ingress_paths = current_ingress.spec.rules[0].http.paths + current_ingress_paths = list(filter(lambda x: x.backend.service.name != f"instance-{body['instance']}", current_ingress_paths)) + current_ingress.spec.rules[0].http.paths = current_ingress_paths - networking.patch_namespaced_ingress(ingress, namespace, current_ingress) + networking.patch_namespaced_ingress(ingress, namespace, current_ingress) + finally: + lock.release_lock() return "Ok"