diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2024-02-16 03:36:38 +0200 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2024-02-16 03:36:38 +0200 |
commit | bf82f43790a675dd1b9522a7799357e61e7aa635 (patch) | |
tree | 07c459ce59aadc3b8157112635c736976685ae20 /src/backend/tcop/postgres.c | |
parent | 51efe38cb92f4b15b68811bcce9ab878fbc71ea5 (diff) | |
download | postgresql-bf82f43790a675dd1b9522a7799357e61e7aa635.tar.gz postgresql-bf82f43790a675dd1b9522a7799357e61e7aa635.zip |
Followup fixes for transaction_timeout
Don't deal with transaction timeout in PostgresMain(). Instead, release
transaction timeout activated by StartTransaction() in
CommitTransaction()/AbortTransaction()/PrepareTransaction(). Deal with both
enabling and disabling transaction timeout in assign_transaction_timeout().
Also, remove potentially flaky timeouts-long isolation test, which has no
guarantees to pass on slow/busy machines.
Reported-by: Andres Freund
Discussion: https://postgr.es/m/20240215230856.pc6k57tqxt7fhldm%40awork3.anarazel.de
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index de9f5d1a6c4..2c63b7875a3 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -3647,9 +3647,17 @@ check_log_stats(bool *newval, void **extra, GucSource source) void assign_transaction_timeout(int newval, void *extra) { - if (TransactionTimeout <= 0 && - get_timeout_active(TRANSACTION_TIMEOUT)) - disable_timeout(TRANSACTION_TIMEOUT, false); + if (IsTransactionState()) + { + /* + * If transaction_timeout GUC has changes within the transaction block + * enable or disable the timer correspondingly. + */ + if (newval > 0 && !get_timeout_active(TRANSACTION_TIMEOUT)) + enable_timeout_after(TRANSACTION_TIMEOUT, newval); + else if (newval <= 0 && get_timeout_active(TRANSACTION_TIMEOUT)) + disable_timeout(TRANSACTION_TIMEOUT, false); + } } @@ -4510,11 +4518,6 @@ PostgresMain(const char *dbname, const char *username) enable_timeout_after(IDLE_IN_TRANSACTION_SESSION_TIMEOUT, IdleInTransactionSessionTimeout); } - - /* Schedule or reschedule transaction timeout */ - if (TransactionTimeout > 0 && !get_timeout_active(TRANSACTION_TIMEOUT)) - enable_timeout_after(TRANSACTION_TIMEOUT, - TransactionTimeout); } else if (IsTransactionOrTransactionBlock()) { @@ -4529,11 +4532,6 @@ PostgresMain(const char *dbname, const char *username) enable_timeout_after(IDLE_IN_TRANSACTION_SESSION_TIMEOUT, IdleInTransactionSessionTimeout); } - - /* Schedule or reschedule transaction timeout */ - if (TransactionTimeout > 0 && !get_timeout_active(TRANSACTION_TIMEOUT)) - enable_timeout_after(TRANSACTION_TIMEOUT, - TransactionTimeout); } else { @@ -4586,13 +4584,6 @@ PostgresMain(const char *dbname, const char *username) enable_timeout_after(IDLE_SESSION_TIMEOUT, IdleSessionTimeout); } - - /* - * If GUC is changed then it's handled in - * assign_transaction_timeout(). - */ - if (TransactionTimeout > 0 && get_timeout_active(TRANSACTION_TIMEOUT)) - disable_timeout(TRANSACTION_TIMEOUT, false); } /* Report any recently-changed GUC options */ |