]> granicus.if.org Git - postgresql/commit
Reorder steps in ConditionVariablePrepareToSleep for more safety.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 6 Jan 2018 00:42:49 +0000 (19:42 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 6 Jan 2018 00:42:49 +0000 (19:42 -0500)
commit3cac0ec85992829c160bdd8a370dd4676d42f58c
tree963916a8fb133aebd8ebc5b729ef73b096b0fe43
parentaced5a92bf46532466417ab485bc94006cf60d91
Reorder steps in ConditionVariablePrepareToSleep for more safety.

In the admittedly-very-unlikely case that AddWaitEventToSet fails,
ConditionVariablePrepareToSleep would error out after already having
set cv_sleep_target, which is probably bad, and after having already
set cv_wait_event_set, which is very bad.  Transaction abort might or
might not clean up cv_sleep_target properly; but there is nothing
that would be aware that the WaitEventSet wasn't fully constructed,
so that all future condition variable sleeps would be broken.
We can easily guard against these hazards with slight restructuring.

Back-patch to v10 where condition_variable.c was introduced.

Discussion: https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com
src/backend/storage/lmgr/condition_variable.c