Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRYdz-000000014up-0GGH for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Nov 2026 17:31:27 +0000 Received: from localhost ([127.0.0.1]:47742 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xRYds-0000000451k-1yFa for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Nov 2026 17:31:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:52016) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRU81-0000000GMFd-3FOk for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 12:42:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRU7y-00000000dyO-40vH for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 12:42:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=MBvKHO1MfmdryyC33lrSqh13CYmH52RrtBWtB8v7wbI=; b=zwG7/89Q859XYb80SmbPVLChwV GmCQquv1tNIAcSHyjhUXLszs4ojy4OklG+1gS/tNespNgt+foM9fFGjbcYZBatwptR7Zldg6ck+M5 RVApCUNAkkvXWYnNoCGPWiaddJteiZ7F+ENRKs72gnzuUgeijb2n3+7tKVWVL1e6W8BKJGX+jqyOi 5fJxt93SqH91fReDOR3KrEXZdet+I4A6KvXPhV9VH7xfUuy9F7LvQyEUn5CfgQECLULwo+Uo5HpSl vm4PD9Tb+Uq4Hd8Vb6WbdeYLGIHOShzq4XmVt3zxQUeu0ojXyRgYqphuXZYL7BVycrcoiB6NHIdY2 pGDto2bA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRU7w-00000001VXD-3maG for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 12:42:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xRU7v-00000003oxE-1Wul for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 12:42:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19896: transaction_timeout misbehaves after ROLLBACK TO SAVEPOINT and after errors To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: nickevanoorschot@gmail.com Reply-To: nickevanoorschot@gmail.com, pgsql-bugs@lists.postgresql.org Date: Thu, 12 Nov 2026 12:41:55 +0000 Message-ID: <19896-555a806fe6352359@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19896 Logged by: Nicke van Oorschot Email address: nickevanoorschot@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 22.04.5 LTS Description: =20 PostgreSQL versions: 18.6; 20devel (development snapshot postgresql-snapshot.tar.bz2 of 2026-11-12 04:22 UTC, master at debfb3c8a8c93e7bcc3638523b7ffc0846cc2db8). First observed on 18.1 ("PostgreSQL 18.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 15.2.0) 15.2.0, 64-bit"). Documentation of transaction_timeout: "Terminate any session that spans longer than the specified amount of time in a transaction." The cases below differ from that. Each script was run with "psql -X -f " against a freshly initialised cluster with default settings. Output below is from 18.6; 20devel gives the same output apart from the LOCATION line numbers. Case 1: a timeout set inside a rolled-back savepoint terminates a later transaction --- case1.sql \set VERBOSITY verbose -- Transaction 1 sets transaction_timeout inside a savepoint and rolls the savepoint back. BEGIN; SELECT now() AS transaction_1_start; SAVEPOINT s; SET LOCAL transaction_timeout =3D '2s'; ROLLBACK TO SAVEPOINT s; SHOW transaction_timeout; COMMIT; -- Transaction 2 sets a 10 s transaction_timeout and runs for 3 s. BEGIN; SELECT now() AS transaction_2_start; SET LOCAL transaction_timeout =3D '10s'; SELECT pg_sleep(3); COMMIT; SELECT 'transaction 2 committed' AS result; --- Output: BEGIN transaction_1_start ------------------------------- 2026-11-12 11:33:03.520214+00 (1 row) SAVEPOINT SET ROLLBACK transaction_timeout --------------------- 0 (1 row) COMMIT BEGIN transaction_2_start ------------------------------- 2026-11-12 11:33:03.520757+00 (1 row) SET psql:case1.sql:14: FATAL: 25P04: terminating connection due to transaction timeout LOCATION: ProcessInterrupts, postgres.c:3498 psql:case1.sql:14: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. psql:case1.sql:14: error: connection to server was lost Server log: 2026-11-12 11:33:05.520 UTC [297561] FATAL: terminating connection due to transaction timeout 2026-11-12 11:33:05.520 UTC [297561] STATEMENT: SELECT pg_sleep(3); The connection is terminated 2 s after transaction 1 started, while transaction 2 has run for less than 2 s with a 10 s transaction_timeout. Expected: transaction 2 completes and "transaction 2 committed" is returned. Transaction 1 ended with transaction_timeout =3D 0, and transaction 2 stays within its 10= s. Case 2: after an error and ROLLBACK TO SAVEPOINT, the transaction is not terminated --- case2.sql \set VERBOSITY verbose -- The transaction sets a 2 s transaction_timeout, recovers from an error with ROLLBACK TO SAVEPOINT, and runs for 3 s. BEGIN; SET LOCAL transaction_timeout =3D '2s'; SAVEPOINT s; SELECT 1/0; ROLLBACK TO SAVEPOINT s; SHOW transaction_timeout; SELECT pg_sleep(3); COMMIT; SELECT 'transaction committed after 3 s' AS result; --- Output: BEGIN SET SAVEPOINT psql:case2.sql:6: ERROR: 22012: division by zero LOCATION: int4div, int.c:870 ROLLBACK transaction_timeout --------------------- 2s (1 row) pg_sleep ---------- (1 row) COMMIT result --------------------------------- transaction committed after 3 s (1 row) Expected: the connection is terminated 2 s into the transaction, during pg_sleep(3), and the transaction does not commit. The same script with "SELECT 1;" instead of "SELECT 1/0;" is terminated as expected: psql:case2_control.sql:8: FATAL: 25P04: terminating connection due to transaction timeout Setting the timeout for the session ("SET transaction_timeout =3D '2s';" before BEGIN, no SET LOCAL) gives the same result as case 2: the transaction commits after 3 s. Case 3: an aborted transaction is not terminated --- case3.sql \set VERBOSITY verbose -- The transaction sets a 2 s transaction_timeout, fails, and stays open (aborted) for 3 s. BEGIN; SET LOCAL transaction_timeout =3D '2s'; SELECT 1/0; \! sleep 3 ROLLBACK; SELECT 'connection still open after 3 s' AS result; --- Output: BEGIN SET psql:case3.sql:5: ERROR: 22012: division by zero LOCATION: int4div, int.c:870 ROLLBACK result --------------------------------- connection still open after 3 s (1 row) Expected: the connection is terminated 2 s into the transaction, while it is open in the aborted state. Environment of the 18.6 and 20devel runs: - Built from the source tarballs with ./configure --without-readline --without-zlib --without-icu --without-openssl; make; make install (no other deviation from the installation instructions) - Cluster: initdb -A trust -U postgres, no changes to postgresql.conf - Server started with: pg_ctl -o "-p -k -c listen_addresses=3D''" start - psql from the same build, run with -X (no .psqlrc) - OS: Ubuntu 22.04.5 LTS, Linux 7.0.0-43-generic x86_64, glibc 2.35 - Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0 - CPU: AMD Ryzen 9 7940HS (16 threads), 53 GB RAM