pgsql: Initialize TransactionState and user ID consistently attransact

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема pgsql: Initialize TransactionState and user ID consistently attransact
Дата
Msg-id E1gMpwA-0006Cn-2W@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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

Branch
------
REL9_4_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e85b729375ed33b478aafbb981cd29cb31c58370

Modified Files
--------------
src/backend/access/transam/xact.c | 48 +++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 22 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Add flag values in WAL description to all heap records
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: pgsql: Add flag values in WAL description to all heap records