pgsql: Fix race condition in enum value comparisons.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix race condition in enum value comparisons.
Date: 2012-07-01 21:13:19
Message-ID: E1SlRSJ-0007gt-8J@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix race condition in enum value comparisons.

When (re) loading the typcache comparison cache for an enum type's values,
use an up-to-date MVCC snapshot, not the transaction's existing snapshot.
This avoids problems if we encounter an enum OID that was created since our
transaction started. Per report from Andres Freund and diagnosis by Robert
Haas.

To ensure this is safe even if enum comparison manages to get invoked
before we've set a transaction snapshot, tweak GetLatestSnapshot to
redirect to GetTransactionSnapshot instead of throwing error when
FirstSnapshotSet is false. The existing uses of GetLatestSnapshot (in
ri_triggers.c) don't care since they couldn't be invoked except in a
transaction that's already done some work --- but it seems just conceivable
that this might not be true of enums, especially if we ever choose to use
enums in system catalogs.

Note that the comparable coding in enum_endpoint and enum_range_internal
remains GetTransactionSnapshot; this is perhaps debatable, but if we
changed it those functions would have to be marked volatile, which doesn't
seem attractive.

Back-patch to 9.1 where ALTER TYPE ADD VALUE was added.

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/af4f029675ea2550f12d0b25efb4a673f5c08b08

Modified Files
--------------
src/backend/utils/cache/typcache.c | 2 +-
src/backend/utils/time/snapmgr.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2012-07-02 13:49:27 pgsql: Make walsender more responsive.
Previous Message Tom Lane 2012-07-01 02:28:25 pgsql: Suppress compiler warnings in readfuncs.c.