]> granicus.if.org Git - postgresql/commit
Initialize TransactionState and user ID consistently at transaction start
authorMichael Paquier <michael@paquier.xyz>
Wed, 14 Nov 2018 07:48:22 +0000 (16:48 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 14 Nov 2018 07:48:22 +0000 (16:48 +0900)
commit5793289c7a45f0cff06985aef49669b697435bf9
tree48fb6e68117697de1a76e83bfcfeeb1efbd27ce8
parentbe38945c6e661cb1d14a3295f4c7608a169f56f3
Initialize TransactionState and user ID consistently at transaction start

If a failure happens when a transaction is starting between the moment
the transaction status is changed from TRANS_DEFAULT to TRANS_START and
the moment the current user ID and security context flags are fetched
via GetUserIdAndSecContext(), or before initializing its basic fields,
then those may get reset to incorrect values when the transaction
aborts, leaving the session in an inconsistent state.

One problem reported is that failing a starting transaction at the first
query of a session could cause several kinds of system crashes on the
follow-up queries.

In order to solve that, move the initialization of the transaction state
fields and the call of GetUserIdAndSecContext() in charge of fetching
the current user ID close to the point where the transaction status is
switched to TRANS_START, where there cannot be any error triggered
in-between, per an idea of Tom Lane.  This properly ensures that the
current user ID, the security context flags and that the basic fields of
TransactionState remain consistent even if the transaction fails while
starting.

Reported-by: Richard Guo
Diagnosed-By: Richard Guo
Author: Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAN_9JTxECSb=pEPcb0a8d+6J+bDcOZ4=DgRo_B7Y5gRHJUM=Rw@mail.gmail.com
Backpatch-through: 9.4
src/backend/access/transam/xact.c