Skip to content

Commit a112efa

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 a46f32e commit a112efa

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/backend/tcop/postgres.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,7 +4147,18 @@ PostgresMain(int argc, char *argv[],
41474147
firstchar = ReadCommand(&input_message);
41484148

41494149
/*
4150-
* (4) disable async signal conditions again.
4150+
* (4) turn off the idle-in-transaction timeout, if active. We do
4151+
* this before step (5) so that any last-moment timeout is certain to
4152+
* be detected in step (5).
4153+
*/
4154+
if (disable_idle_in_transaction_timeout)
4155+
{
4156+
disable_timeout(IDLE_IN_TRANSACTION_SESSION_TIMEOUT, false);
4157+
disable_idle_in_transaction_timeout = false;
4158+
}
4159+
4160+
/*
4161+
* (5) disable async signal conditions again.
41514162
*
41524163
* Query cancel is supposed to be a no-op when there is no query in
41534164
* progress, so if a query cancel arrived while we were idle, just
@@ -4158,15 +4169,6 @@ PostgresMain(int argc, char *argv[],
41584169
CHECK_FOR_INTERRUPTS();
41594170
DoingCommandRead = false;
41604171

4161-
/*
4162-
* (5) turn off the idle-in-transaction timeout
4163-
*/
4164-
if (disable_idle_in_transaction_timeout)
4165-
{
4166-
disable_timeout(IDLE_IN_TRANSACTION_SESSION_TIMEOUT, false);
4167-
disable_idle_in_transaction_timeout = false;
4168-
}
4169-
41704172
/*
41714173
* (6) check for any other interesting events that happened while we
41724174
* slept.

0 commit comments

Comments
 (0)