From b173169528cba8f33fa0b3b397fa1e474f5653a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Falconnier?= Date: Sun, 8 Sep 2024 15:35:55 +0200 Subject: [PATCH] Use table lock on santa_targetcounter to avoid deadlocks --- zentral/contrib/santa/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zentral/contrib/santa/utils.py b/zentral/contrib/santa/utils.py index 9762c37bda..083a866a3d 100644 --- a/zentral/contrib/santa/utils.py +++ b/zentral/contrib/santa/utils.py @@ -150,6 +150,9 @@ def update_or_create_targets(configuration, targets): ') select * from observed_targets;' ) with connection.cursor() as cursor: + # To avoid deadlocks between transactions updating the same counters we need to lock the table. + # TODO find a better way. + cursor.execute("LOCK TABLE ONLY santa_targetcounter IN SHARE ROW EXCLUSIVE MODE") result = psycopg2.extras.execute_values( cursor, query, ((target_type.value, target_identifier, configuration.id,