Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 07a601e

Browse files
committed
Avoid crashing in GetOldestSnapshot() if there are no known snapshots.
The sole caller expects NULL to be returned in such a case, so make it so and document it. Per reports from Andreas Seltenreich and Regina Obe. This doesn't really fix their problem, as now their RETURNING queries will say "ERROR: no known snapshots", but in any case this function should not dump core in a reasonably-foreseeable situation. Report: <[email protected]> Report: <[email protected]>
1 parent bcbecbc commit 07a601e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/backend/utils/time/snapmgr.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,14 @@ GetLatestSnapshot(void)
399399
/*
400400
* GetOldestSnapshot
401401
*
402-
* Get the oldest known snapshot, as judged by the LSN.
402+
* Get the transaction's oldest known snapshot, as judged by the LSN.
403+
* Will return NULL if there are no active or registered snapshots.
403404
*/
404405
Snapshot
405406
GetOldestSnapshot(void)
406407
{
407408
Snapshot OldestRegisteredSnapshot = NULL;
408409
XLogRecPtr RegisteredLSN = InvalidXLogRecPtr;
409-
XLogRecPtr ActiveLSN = InvalidXLogRecPtr;
410410

411411
if (!pairingheap_is_empty(&RegisteredSnapshots))
412412
{
@@ -416,10 +416,12 @@ GetOldestSnapshot(void)
416416
}
417417

418418
if (OldestActiveSnapshot != NULL)
419-
ActiveLSN = OldestActiveSnapshot->as_snap->lsn;
419+
{
420+
XLogRecPtr ActiveLSN = OldestActiveSnapshot->as_snap->lsn;
420421

421-
if (XLogRecPtrIsInvalid(RegisteredLSN) || RegisteredLSN > ActiveLSN)
422-
return OldestActiveSnapshot->as_snap;
422+
if (XLogRecPtrIsInvalid(RegisteredLSN) || RegisteredLSN > ActiveLSN)
423+
return OldestActiveSnapshot->as_snap;
424+
}
423425

424426
return OldestRegisteredSnapshot;
425427
}

0 commit comments

Comments
 (0)