Skip to content

Commit 0cb8bf2

Browse files
committed
Avoid infinite loop in visibility check
1 parent 7f01f7f commit 0cb8bf2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

contrib/mmts/multimaster.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ typedef enum
9696
#define MTM_MAP_SIZE 1003
9797
#define MIN_WAIT_TIMEOUT 1000
9898
#define MAX_WAIT_TIMEOUT 100000
99+
#define MAX_WAIT_LOOPS 100
99100
#define STATUS_POLL_DELAY USECS_PER_SEC
100101

101102
void _PG_init(void);
@@ -419,8 +420,9 @@ bool MtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
419420
static timestamp_t maxSleepTime;
420421
#endif
421422
timestamp_t delay = MIN_WAIT_TIMEOUT;
423+
int i;
422424
Assert(xid != InvalidTransactionId);
423-
425+
424426
if (!MtmUseDtm) {
425427
return PgXidInMVCCSnapshot(xid, snapshot);
426428
}
@@ -431,7 +433,8 @@ bool MtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
431433
firstReportTime = MtmGetCurrentTime();
432434
}
433435
#endif
434-
while (true)
436+
437+
for (i = 0; i < MAX_WAIT_LOOPS; i++)
435438
{
436439
MtmTransState* ts = (MtmTransState*)hash_search(MtmXid2State, &xid, HASH_FIND, NULL);
437440
if (ts != NULL && ts->status != TRANSACTION_STATUS_IN_PROGRESS)
@@ -484,11 +487,13 @@ bool MtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
484487
else
485488
{
486489
MTM_LOG4("%d: visibility check is skept for transaction %u in snapshot %lu", MyProcPid, xid, MtmTx.snapshot);
487-
break;
490+
MtmUnlock();
491+
return PgXidInMVCCSnapshot(xid, snapshot);
488492
}
489493
}
490494
MtmUnlock();
491-
return PgXidInMVCCSnapshot(xid, snapshot);
495+
elog(ERROR, "Failed to get status of XID %d", xid);
496+
return true;
492497
}
493498

494499

@@ -1200,7 +1205,7 @@ static void MtmEnableNode(int nodeId)
12001205

12011206
void MtmRecoveryCompleted(void)
12021207
{
1203-
MTM_LOG1("Recovery of node %d is completed, disabled mask=%lx, reconnect mask=%ld, live nodes=%d",
1208+
MTM_LOG1("Recovery of node %d is completed, disabled mask=%lx, reconnect mask=%lx, live nodes=%d",
12041209
MtmNodeId, Mtm->disabledNodeMask, Mtm->reconnectMask, Mtm->nLiveNodes);
12051210
MtmLock(LW_EXCLUSIVE);
12061211
Mtm->recoverySlot = 0;

0 commit comments

Comments
 (0)