Skip to content

Commit

Permalink
Use table lock on santa_targetcounter to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
np5 committed Sep 8, 2024
1 parent 182cb78 commit b173169
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions zentral/contrib/santa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b173169

Please sign in to comment.