Skip to content

Commit e8528a8

Browse files
committed
Fix deadlock at startup, if max_prepared_transactions is too small.
When the startup process recovers transactions by scanning pg_twophase directory, it should clear MyLockedGxact after it's done processing each transaction. Like we do during normal operation, at PREPARE TRANSACTION. Otherwise, if the startup process exits due to an error, it will try to clear the locking_backend field of the last recovered transaction. That's usually harmless, but if the error happens in MarkAsPreparing, while holding TwoPhaseStateLock, the shmem-exit hook will try to acquire TwoPhaseStateLock again, and deadlock with itself. This fixes bug #13128 reported by Grant McAlister. The bug was introduced by commit bb38fb0, so backpatch to all supported versions like that commit.
1 parent 42f5227 commit e8528a8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/backend/access/transam/twophase.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,12 @@ RecoverPreparedTransactions(void)
20182018
if (InHotStandby)
20192019
StandbyReleaseLockTree(xid, hdr->nsubxacts, subxids);
20202020

2021+
/*
2022+
* We're done with recovering this transaction. Clear MyLockedGxact,
2023+
* like we do in PrepareTransaction() during normal operation.
2024+
*/
2025+
PostPrepare_Twophase();
2026+
20212027
pfree(buf);
20222028
}
20232029
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy