Re: Possible Bug in relation_open

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Pradeep Kumar <spradeepkumar29(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Possible Bug in relation_open
Date: 2024-05-21 15:12:40
Message-ID: 3911828.1716304360@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Tue, May 21, 2024 at 9:58 AM Pradeep Kumar <spradeepkumar29(at)gmail(dot)com> wrote:
>> If the user tries to open the relation in RangeVar and NoLock mode calling table_openrv(relation, NoLock), it will internally call relation_openrv()-->relation_open(). In relation_open() we checking the Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES); , here we expecting the lockmode is NoLock or greater than that, but in same function again we checking this assert case Assert(lockmode != NoLock || IsBootstrapProcessingMode() || CheckRelationLockedByMe(r, AccessShareLock, true)); , here we are expecting (lockmode != NoLock) , so why are there two cases that contradict? and What if the user tries to open the relation in NoLock mode? and that will definitely cause the assert failure, Suppose the user who writes some extension and reads some relation oid that is constant, and wants to acquire NoLock?, need some clarification on this.

> You need to acquire a lock. Otherwise, the relcache entry could change
> underneath you while you're accessing it, which would result in
> PostgreSQL crashing.

To clarify: the rule is that it's only allowed to pass NoLock if you
know for certain that some suitable lock on that relation is already
held by the current query. That's why these conditions are complicated.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Burroughs 2024-05-21 15:23:36 Re: libpq compression (part 3)
Previous Message Andres Freund 2024-05-21 15:04:04 Re: zlib detection in Meson on Windows broken?