Skip to content

Commit b8d0cda

Browse files
committed
Further second thoughts about idle_session_timeout patch.
On reflection, the order of operations in PostgresMain() is wrong. These timeouts ought to be shut down before, not after, we do the post-command-read CHECK_FOR_INTERRUPTS, to guarantee that any timeout error will be detected there rather than at some ill-defined later point (possibly after having wasted a lot of work). This is really an error in the original idle_in_transaction_timeout patch, so back-patch to 9.6 where that was introduced.
1 parent ebb5457 commit b8d0cda

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/backend/tcop/postgres.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,22 +4323,11 @@ PostgresMain(int argc, char *argv[],
43234323
firstchar = ReadCommand(&input_message);
43244324

43254325
/*
4326-
* (4) disable async signal conditions again.
4326+
* (4) turn off the idle-in-transaction and idle-session timeouts, if
4327+
* active. We do this before step (5) so that any last-moment timeout
4328+
* is certain to be detected in step (5).
43274329
*
4328-
* Query cancel is supposed to be a no-op when there is no query in
4329-
* progress, so if a query cancel arrived while we were idle, just
4330-
* reset QueryCancelPending. ProcessInterrupts() has that effect when
4331-
* it's called when DoingCommandRead is set, so check for interrupts
4332-
* before resetting DoingCommandRead.
4333-
*/
4334-
CHECK_FOR_INTERRUPTS();
4335-
DoingCommandRead = false;
4336-
4337-
/*
4338-
* (5) turn off the idle-in-transaction and idle-session timeouts, if
4339-
* active.
4340-
*
4341-
* At most one of these two will be active, so there's no need to
4330+
* At most one of these timeouts will be active, so there's no need to
43424331
* worry about combining the timeout.c calls into one.
43434332
*/
43444333
if (idle_in_transaction_timeout_enabled)
@@ -4352,6 +4341,18 @@ PostgresMain(int argc, char *argv[],
43524341
idle_session_timeout_enabled = false;
43534342
}
43544343

4344+
/*
4345+
* (5) disable async signal conditions again.
4346+
*
4347+
* Query cancel is supposed to be a no-op when there is no query in
4348+
* progress, so if a query cancel arrived while we were idle, just
4349+
* reset QueryCancelPending. ProcessInterrupts() has that effect when
4350+
* it's called when DoingCommandRead is set, so check for interrupts
4351+
* before resetting DoingCommandRead.
4352+
*/
4353+
CHECK_FOR_INTERRUPTS();
4354+
DoingCommandRead = false;
4355+
43554356
/*
43564357
* (6) check for any other interesting events that happened while we
43574358
* slept.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy