@@ -3242,14 +3242,28 @@ ProcessInterrupts(void)
3242
3242
3243
3243
if (IdleInTransactionSessionTimeoutPending )
3244
3244
{
3245
- /* Has the timeout setting changed since last we looked? */
3245
+ /*
3246
+ * If the GUC has been reset to zero, ignore the signal. This is
3247
+ * important because the GUC update itself won't disable any pending
3248
+ * interrupt.
3249
+ */
3246
3250
if (IdleInTransactionSessionTimeout > 0 )
3247
3251
ereport (FATAL ,
3248
3252
(errcode (ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT ),
3249
3253
errmsg ("terminating connection due to idle-in-transaction timeout" )));
3250
3254
else
3251
3255
IdleInTransactionSessionTimeoutPending = false;
3256
+ }
3252
3257
3258
+ if (IdleSessionTimeoutPending )
3259
+ {
3260
+ /* As above, ignore the signal if the GUC has been reset to zero. */
3261
+ if (IdleSessionTimeout > 0 )
3262
+ ereport (FATAL ,
3263
+ (errcode (ERRCODE_IDLE_SESSION_TIMEOUT ),
3264
+ errmsg ("terminating connection due to idle-session timeout" )));
3265
+ else
3266
+ IdleSessionTimeoutPending = false;
3253
3267
}
3254
3268
3255
3269
if (ProcSignalBarrierPending )
@@ -3826,7 +3840,8 @@ PostgresMain(int argc, char *argv[],
3826
3840
StringInfoData input_message ;
3827
3841
sigjmp_buf local_sigjmp_buf ;
3828
3842
volatile bool send_ready_for_query = true;
3829
- bool disable_idle_in_transaction_timeout = false;
3843
+ bool idle_in_transaction_timeout_enabled = false;
3844
+ bool idle_session_timeout_enabled = false;
3830
3845
3831
3846
/* Initialize startup process environment if necessary. */
3832
3847
if (!IsUnderPostmaster )
@@ -4228,6 +4243,8 @@ PostgresMain(int argc, char *argv[],
4228
4243
* processing of batched messages, and because we don't want to report
4229
4244
* uncommitted updates (that confuses autovacuum). The notification
4230
4245
* processor wants a call too, if we are not in a transaction block.
4246
+ *
4247
+ * Also, if an idle timeout is enabled, start the timer for that.
4231
4248
*/
4232
4249
if (send_ready_for_query )
4233
4250
{
@@ -4239,7 +4256,7 @@ PostgresMain(int argc, char *argv[],
4239
4256
/* Start the idle-in-transaction timer */
4240
4257
if (IdleInTransactionSessionTimeout > 0 )
4241
4258
{
4242
- disable_idle_in_transaction_timeout = true;
4259
+ idle_in_transaction_timeout_enabled = true;
4243
4260
enable_timeout_after (IDLE_IN_TRANSACTION_SESSION_TIMEOUT ,
4244
4261
IdleInTransactionSessionTimeout );
4245
4262
}
@@ -4252,7 +4269,7 @@ PostgresMain(int argc, char *argv[],
4252
4269
/* Start the idle-in-transaction timer */
4253
4270
if (IdleInTransactionSessionTimeout > 0 )
4254
4271
{
4255
- disable_idle_in_transaction_timeout = true;
4272
+ idle_in_transaction_timeout_enabled = true;
4256
4273
enable_timeout_after (IDLE_IN_TRANSACTION_SESSION_TIMEOUT ,
4257
4274
IdleInTransactionSessionTimeout );
4258
4275
}
@@ -4275,6 +4292,14 @@ PostgresMain(int argc, char *argv[],
4275
4292
4276
4293
set_ps_display ("idle" );
4277
4294
pgstat_report_activity (STATE_IDLE ,NULL );
4295
+
4296
+ /* Start the idle-session timer */
4297
+ if (IdleSessionTimeout > 0 )
4298
+ {
4299
+ idle_session_timeout_enabled = true;
4300
+ enable_timeout_after (IDLE_SESSION_TIMEOUT ,
4301
+ IdleSessionTimeout );
4302
+ }
4278
4303
}
4279
4304
4280
4305
/* Report any recently-changed GUC options */
@@ -4310,12 +4335,21 @@ PostgresMain(int argc, char *argv[],
4310
4335
DoingCommandRead = false;
4311
4336
4312
4337
/*
4313
- * (5) turn off the idle-in-transaction timeout
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
4342
+ * worry about combining the timeout.c calls into one.
4314
4343
*/
4315
- if (disable_idle_in_transaction_timeout )
4344
+ if (idle_in_transaction_timeout_enabled )
4316
4345
{
4317
4346
disable_timeout (IDLE_IN_TRANSACTION_SESSION_TIMEOUT , false);
4318
- disable_idle_in_transaction_timeout = false;
4347
+ idle_in_transaction_timeout_enabled = false;
4348
+ }
4349
+ if (idle_session_timeout_enabled )
4350
+ {
4351
+ disable_timeout (IDLE_SESSION_TIMEOUT , false);
4352
+ idle_session_timeout_enabled = false;
4319
4353
}
4320
4354
4321
4355
/*