Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use table lock on santa_targetcounter to avoid deadlocks #1053

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading