Fix LISTEN/NOTIFY race condition reported by Laurent Birtz, by postponing

Tom Lane <tgl@sss.pgh.pa.us>

Commit: d272e2f8d8535eca4033fdba15982c1576452253
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2008-03-12T20:12:39Z
Releases: 8.0.16
Fix LISTEN/NOTIFY race condition reported by Laurent Birtz, by postponing
pg_listener modifications commanded by LISTEN and UNLISTEN until the end
of the current transaction.  This allows us to hold the ExclusiveLock on
pg_listener until after commit, with no greater risk of deadlock than there
was before.  Aside from fixing the race condition, this gets rid of a
truly ugly kludge that was there before, namely having to ignore
HeapTupleBeingUpdated failures during NOTIFY.  There is a small potential
incompatibility, which is that if a transaction issues LISTEN or UNLISTEN
and then looks into pg_listener before committing, it won't see any resulting
row insertion or deletion, where before it would have.  It seems unlikely
that anyone would be depending on that, though.

Files

PathChange+/−
src/backend/commands/async.c modified +377 −345