@@ -3242,14 +3242,28 @@ ProcessInterrupts(void)
32423242
32433243 if (IdleInTransactionSessionTimeoutPending )
32443244 {
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+ */
32463250 if (IdleInTransactionSessionTimeout > 0 )
32473251 ereport (FATAL ,
32483252 (errcode (ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT ),
32493253 errmsg ("terminating connection due to idle-in-transaction timeout" )));
32503254 else
32513255 IdleInTransactionSessionTimeoutPending = false;
3256+ }
32523257
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;
32533267 }
32543268
32553269 if (ProcSignalBarrierPending )
@@ -3826,7 +3840,8 @@ PostgresMain(int argc, char *argv[],
38263840 StringInfoData input_message ;
38273841 sigjmp_buf local_sigjmp_buf ;
38283842 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;
38303845
38313846 /* Initialize startup process environment if necessary. */
38323847 if (!IsUnderPostmaster )
@@ -4228,6 +4243,8 @@ PostgresMain(int argc, char *argv[],
42284243 * processing of batched messages, and because we don't want to report
42294244 * uncommitted updates (that confuses autovacuum). The notification
42304245 * 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.
42314248 */
42324249 if (send_ready_for_query )
42334250 {
@@ -4239,7 +4256,7 @@ PostgresMain(int argc, char *argv[],
42394256 /* Start the idle-in-transaction timer */
42404257 if (IdleInTransactionSessionTimeout > 0 )
42414258 {
4242- disable_idle_in_transaction_timeout = true;
4259+ idle_in_transaction_timeout_enabled = true;
42434260 enable_timeout_after (IDLE_IN_TRANSACTION_SESSION_TIMEOUT ,
42444261 IdleInTransactionSessionTimeout );
42454262 }
@@ -4252,7 +4269,7 @@ PostgresMain(int argc, char *argv[],
42524269 /* Start the idle-in-transaction timer */
42534270 if (IdleInTransactionSessionTimeout > 0 )
42544271 {
4255- disable_idle_in_transaction_timeout = true;
4272+ idle_in_transaction_timeout_enabled = true;
42564273 enable_timeout_after (IDLE_IN_TRANSACTION_SESSION_TIMEOUT ,
42574274 IdleInTransactionSessionTimeout );
42584275 }
@@ -4275,6 +4292,14 @@ PostgresMain(int argc, char *argv[],
42754292
42764293 set_ps_display ("idle" );
42774294 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+ }
42784303 }
42794304
42804305 /* Report any recently-changed GUC options */
@@ -4310,12 +4335,21 @@ PostgresMain(int argc, char *argv[],
43104335 DoingCommandRead = false;
43114336
43124337 /*
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.
43144343 */
4315- if (disable_idle_in_transaction_timeout )
4344+ if (idle_in_transaction_timeout_enabled )
43164345 {
43174346 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;
43194353 }
43204354
43214355 /*
0 commit comments