Re: [sqlsmith] Crash in GetOldestSnapshot()

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Andreas Seltenreich <seltenreich(at)gmx(dot)de>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [sqlsmith] Crash in GetOldestSnapshot()
Date: 2016-08-06 12:33:47
Message-ID: CAA4eK1LiRxT_iPfJ=uK13tLCtaGAQqn_YOY=6zCBqoi2mW333A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Aug 6, 2016 at 5:51 PM, Andrew Gierth
<andrew(at)tao11(dot)riddles(dot)org(dot)uk> wrote:
>>>>>> "Andreas" == Andreas Seltenreich <seltenreich(at)gmx(dot)de> writes:
>
> 418 if (OldestActiveSnapshot != NULL)
> 419 ActiveLSN = OldestActiveSnapshot->as_snap->lsn;
> 420
> 421 if (XLogRecPtrIsInvalid(RegisteredLSN) || RegisteredLSN > ActiveLSN)
> 422 return OldestActiveSnapshot->as_snap;
>
> This second conditional should clearly be inside the first one...
>

Sure, that is the reason of crash, but even if we do that it will lead
to an error "no known snapshots". Here, what is going on is that we
initialized toast snapshot when there is no active snapshot in the
backend, so GetOldestSnapshot() won't return any snapshot. I think
for such situations, we need to initialize the lsn and whenTaken of
ToastSnapshot as we do in GetSnapshotData() [1]. We need to do this
when snapshot returned by GetOldestSnapshot() is NULL.

Thoughts?

[1]
In below code
if (old_snapshot_threshold < 0)
{
..
}
else
{
/*
* Capture the current time and WAL stream location in case this
* snapshot becomes old enough to need to fall back on the special
* "old snapshot" logic.
*/
snapshot->lsn = GetXLogInsertRecPtr();
snapshot->whenTaken = GetSnapshotCurrentTimestamp();
MaintainOldSnapshotTimeMapping(snapshot->whenTaken, xmin);
}

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Gierth 2016-08-06 13:00:51 Re: [sqlsmith] Crash in GetOldestSnapshot()
Previous Message Andrew Gierth 2016-08-06 12:21:02 Re: [sqlsmith] Crash in GetOldestSnapshot()