Skip to content

Commit f247ce3

Browse files
committed
Prevent deadlocks
1 parent 11c12b8 commit f247ce3

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/ServiceControl.Audit.Persistence.PostgreSQL/UnitOfWork/PostgreSQLAuditIngestionUnitOfWork.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public Task RecordSagaSnapshot(SagaSnapshot sagaSnapshot, CancellationToken canc
104104
// Insert or update saga_snapshots table - add new change to the changes array
105105
var cmd = batch.CreateBatchCommand();
106106
cmd.CommandText = @"
107+
SELECT pg_advisory_xact_lock(hashtext(@saga_id));
107108
INSERT INTO saga_snapshots (id, saga_id, saga_type, changes)
108109
VALUES (@saga_id, @saga_id, @saga_type, @new_change)
109110
ON CONFLICT (id) DO UPDATE SET
@@ -123,6 +124,7 @@ public Task RecordKnownEndpoint(KnownEndpoint knownEndpoint, CancellationToken c
123124
// Insert KnownEndpoint into known_endpoints table
124125
var cmd = batch.CreateBatchCommand();
125126
cmd.CommandText = @"
127+
SELECT pg_advisory_xact_lock(hashtext(@id));
126128
INSERT INTO known_endpoints (
127129
id, name, host_id, host, last_seen
128130
) VALUES (

0 commit comments

Comments
 (0)