Skip to content

Commit 388ec04

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 dd31210 commit 388ec04

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/backend/tcop/postgres.c

+12-10
Original file line numberDiff line numberDiff line change
@@ -4069,7 +4069,18 @@ PostgresMain(int argc, char *argv[],
40694069
firstchar = ReadCommand(&input_message);
40704070

40714071
/*
4072-
* (4) disable async signal conditions again.
4072+
* (4) turn off the idle-in-transaction timeout, if active. We do
4073+
* this before step (5) so that any last-moment timeout is certain to
4074+
* be detected in step (5).
4075+
*/
4076+
if (disable_idle_in_transaction_timeout)
4077+
{
4078+
disable_timeout(IDLE_IN_TRANSACTION_SESSION_TIMEOUT, false);
4079+
disable_idle_in_transaction_timeout = false;
4080+
}
4081+
4082+
/*
4083+
* (5) disable async signal conditions again.
40734084
*
40744085
* Query cancel is supposed to be a no-op when there is no query in
40754086
* progress, so if a query cancel arrived while we were idle, just
@@ -4080,15 +4091,6 @@ PostgresMain(int argc, char *argv[],
40804091
CHECK_FOR_INTERRUPTS();
40814092
DoingCommandRead = false;
40824093

4083-
/*
4084-
* (5) turn off the idle-in-transaction timeout
4085-
*/
4086-
if (disable_idle_in_transaction_timeout)
4087-
{
4088-
disable_timeout(IDLE_IN_TRANSACTION_SESSION_TIMEOUT, false);
4089-
disable_idle_in_transaction_timeout = false;
4090-
}
4091-
40924094
/*
40934095
* (6) check for any other interesting events that happened while we
40944096
* slept.

0 commit comments

Comments
 (0)