Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 49c2c5f

Browse files
committed
Fix bugs in GetSafeSnapshotBlockingPids(), introduced in 9600371
While removing the use of SHM_QUEUE from predicate.c, in 9600371, I made two mistakes in GetSafeSnapshotBlockingPids(): - Removed the check for output_size - Previously, when the first loop didn't find a matching proc, sxact would be NULL. But with naive use of dlist_foreach() it ends up as the value of the last iteration. The second issue is the cause of occasional failures in the deadlock-hard and deadlock-soft isolation tests that we have been observing on CI. The issue was very hard to reproduce, as it requires the transactions.sql regression test to run at the same time as the deadlock-{hard,soft} isolation test. I did not find other similar mistakes in 9600371. Discussion: https://postgr.es/m/20230208221145.bwzhancellclrgia@awork3.anarazel.de
1 parent 969509c commit 49c2c5f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/storage/lmgr/predicate.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -1563,29 +1563,36 @@ GetSafeSnapshotBlockingPids(int blocked_pid, int *output, int output_size)
15631563
{
15641564
int num_written = 0;
15651565
dlist_iter iter;
1566-
SERIALIZABLEXACT *sxact = NULL;
1566+
SERIALIZABLEXACT *blocking_sxact = NULL;
15671567

15681568
LWLockAcquire(SerializableXactHashLock, LW_SHARED);
15691569

15701570
/* Find blocked_pid's SERIALIZABLEXACT by linear search. */
15711571
dlist_foreach(iter, &PredXact->activeList)
15721572
{
1573-
sxact = dlist_container(SERIALIZABLEXACT, xactLink, iter.cur);
1573+
SERIALIZABLEXACT *sxact =
1574+
dlist_container(SERIALIZABLEXACT, xactLink, iter.cur);
15741575

15751576
if (sxact->pid == blocked_pid)
1577+
{
1578+
blocking_sxact = sxact;
15761579
break;
1580+
}
15771581
}
15781582

15791583
/* Did we find it, and is it currently waiting in GetSafeSnapshot? */
1580-
if (sxact != NULL && SxactIsDeferrableWaiting(sxact))
1584+
if (blocking_sxact != NULL && SxactIsDeferrableWaiting(blocking_sxact))
15811585
{
15821586
/* Traverse the list of possible unsafe conflicts collecting PIDs. */
1583-
dlist_foreach(iter, &sxact->possibleUnsafeConflicts)
1587+
dlist_foreach(iter, &blocking_sxact->possibleUnsafeConflicts)
15841588
{
15851589
RWConflict possibleUnsafeConflict =
15861590
dlist_container(RWConflictData, inLink, iter.cur);
15871591

15881592
output[num_written++] = possibleUnsafeConflict->sxactOut->pid;
1593+
1594+
if (num_written >= output_size)
1595+
break;
15891596
}
15901597
}
15911598

0 commit comments

Comments
 (0)