public inbox for [email protected]
help / color / mirror / Atom feedFrom: Andrey M. Borodin <[email protected]>
To: Alexander Korotkov <[email protected]>
Cc: Japin Li <[email protected]>
Cc: Peter Smith <[email protected]>
Cc: Junwang Zhao <[email protected]>
Cc: 邱宇航 <[email protected]>
Cc: Fujii Masao <[email protected]>
Cc: Andrew Borodin <[email protected]>
Cc: Michael Paquier <[email protected]>
Cc: Nikolay Samokhvalov <[email protected]>
Cc: pgsql-hackers mailing list <[email protected]>
Cc: pgsql-hackers mailing list <[email protected]>
Cc: Andres Freund <[email protected]>
Subject: Re: Transaction timeout
Date: Wed, 6 Mar 2024 11:22:00 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAPpHfduK9Dzcsr3bVaO10A7M-ik49825oaOq5=Z=4FZGtusgcg@mail.gmail.com>
References: <[email protected]>
<ME3P282MB3166A9BFA45239291EBC5F1CB667A@ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM>
<[email protected]>
<CAHut+PuOdzypMrK3HsSr0F2fyn8VO5z2+EZ=6Sz39QNbBrisHQ@mail.gmail.com>
<[email protected]>
<ME3P282MB316697D91841CF4EE86CF882B6792@ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM>
<[email protected]>
<ME3P282MB3166A01CE3BC1B8B9C846A75B67C2@ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM>
<[email protected]>
<CAPpHfds=ByL_MEZunF7P+AaDJ7xv7LD8kHcV9awWZx5fOJZBRw@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
<ME3P282MB31662287F06AE5D788869D8DB6512@ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM>
<[email protected]>
<CAPpHfduK9Dzcsr3bVaO10A7M-ik49825oaOq5=Z=4FZGtusgcg@mail.gmail.com>
> On 25 Feb 2024, at 21:50, Alexander Korotkov <[email protected]> wrote:
>
> Thank you for the patches. I've pushed the 0001 patch to avoid
> further failures on buildfarm. Let 0004 wait till injections points
> by Mechael are committed.
Thanks!
All prerequisites are committed. I propose something in a line with this patch.
Best regards, Andrey Borodin.
Attachments:
[application/octet-stream] v2-0001-Add-timeouts-TAP-tests.patch (6.9K, ../[email protected]/2-v2-0001-Add-timeouts-TAP-tests.patch)
download | inline diff:
From dcc076b00be7647c5f195845bf0c4917d24b5045 Mon Sep 17 00:00:00 2001
From: "Andrey M. Borodin" <[email protected]>
Date: Wed, 21 Feb 2024 19:34:26 +0300
Subject: [PATCH v2] Add timeouts TAP tests
These tests verify that transaction_timeout, idle_session_timeout
and idle_in_transaction_session_timeout work as expected.
To do so we add injection points in before throwing a FATAL
and test that these injection points are reached.
Discussion: https://postgr.es/m/CAAhFRxiQsRs2Eq5kCo9nXE3HTugsAAJdSQSmxncivebAxdmBjQ%40mail.gmail.com
---
src/backend/tcop/postgres.c | 10 ++
src/test/modules/test_misc/Makefile | 4 +
src/test/modules/test_misc/meson.build | 4 +
src/test/modules/test_misc/t/005_timeouts.pl | 115 +++++++++++++++++++
4 files changed, 133 insertions(+)
create mode 100644 src/test/modules/test_misc/t/005_timeouts.pl
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index aec1b19442..be5cb2cf2c 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -72,6 +72,7 @@
#include "tcop/tcopprot.h"
#include "tcop/utility.h"
#include "utils/guc_hooks.h"
+#include "utils/injection_point.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
@@ -3411,9 +3412,12 @@ ProcessInterrupts(void)
* interrupt.
*/
if (IdleInTransactionSessionTimeout > 0)
+ {
+ INJECTION_POINT("idle-in-transaction-session-timeout");
ereport(FATAL,
(errcode(ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT),
errmsg("terminating connection due to idle-in-transaction timeout")));
+ }
else
IdleInTransactionSessionTimeoutPending = false;
}
@@ -3422,9 +3426,12 @@ ProcessInterrupts(void)
{
/* As above, ignore the signal if the GUC has been reset to zero. */
if (TransactionTimeout > 0)
+ {
+ INJECTION_POINT("transaction-timeout");
ereport(FATAL,
(errcode(ERRCODE_TRANSACTION_TIMEOUT),
errmsg("terminating connection due to transaction timeout")));
+ }
else
TransactionTimeoutPending = false;
}
@@ -3433,9 +3440,12 @@ ProcessInterrupts(void)
{
/* As above, ignore the signal if the GUC has been reset to zero. */
if (IdleSessionTimeout > 0)
+ {
+ INJECTION_POINT("idle-session-timeout");
ereport(FATAL,
(errcode(ERRCODE_IDLE_SESSION_TIMEOUT),
errmsg("terminating connection due to idle-session timeout")));
+ }
else
IdleSessionTimeoutPending = false;
}
diff --git a/src/test/modules/test_misc/Makefile b/src/test/modules/test_misc/Makefile
index 39c6c2014a..a958d156f4 100644
--- a/src/test/modules/test_misc/Makefile
+++ b/src/test/modules/test_misc/Makefile
@@ -2,6 +2,10 @@
TAP_TESTS = 1
+EXTRA_INSTALL=src/test/modules/injection_points
+
+export enable_injection_points enable_injection_points
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/src/test/modules/test_misc/meson.build b/src/test/modules/test_misc/meson.build
index 964d95db26..df2913e893 100644
--- a/src/test/modules/test_misc/meson.build
+++ b/src/test/modules/test_misc/meson.build
@@ -5,11 +5,15 @@ tests += {
'sd': meson.current_source_dir(),
'bd': meson.current_build_dir(),
'tap': {
+ 'env': {
+ 'enable_injection_points': get_option('injection_points') ? 'yes' : 'no',
+ },
'tests': [
't/001_constraint_validation.pl',
't/002_tablespace.pl',
't/003_check_guc.pl',
't/004_io_direct.pl',
+ 't/005_timeouts.pl'
],
},
}
diff --git a/src/test/modules/test_misc/t/005_timeouts.pl b/src/test/modules/test_misc/t/005_timeouts.pl
new file mode 100644
index 0000000000..fa76714816
--- /dev/null
+++ b/src/test/modules/test_misc/t/005_timeouts.pl
@@ -0,0 +1,115 @@
+
+# Copyright (c) 2024, PostgreSQL Global Development Group
+
+use strict;
+use warnings;
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+# Test timeouts that will FATAL-out.
+# This test relies on an injection points to await timeout ocurance.
+# Relying on sleep prooved to be unstable on buildfarm.
+# It's difficult to rely on NOTICE injection point, because FATALed
+# backend can look differently under different circumstances.
+
+if ($ENV{enable_injection_points} ne 'yes')
+{
+ plan skip_all => 'Injection points not supported by this build';
+}
+
+# Node initialization
+my $node = PostgreSQL::Test::Cluster->new('master');
+$node->init();
+$node->start;
+
+$node->safe_psql('postgres', 'CREATE EXTENSION injection_points;');
+$node->safe_psql('postgres',
+ "SELECT injection_points_attach('transaction-timeout', 'wait');");
+
+
+#
+# 1. Test of transaction timeout
+#
+
+my $psql_session =
+ $node->background_psql('postgres');
+
+# Following query will generate a stream of SELECT 1 queries. This is done to
+# excersice transaction timeout in presence of short queries.
+$psql_session->query_until(
+ qr/starting_bg_psql/, q(
+ \echo starting_bg_psql
+ SET transaction_timeout to '10ms';
+ BEGIN;
+ SELECT 1 \watch 0.001
+ \q
+));
+
+# Wait until the backend is in the timeout.
+# In case if anything get broken this waiting will error-out
+$node->wait_for_event('client backend','transaction-timeout');
+
+# Remove injection point.
+$node->safe_psql('postgres',
+ "SELECT injection_points_wakeup('transaction-timeout');");
+
+# If we send \q with $psql_session->quit it can get to pump already closed.
+# So \q is in initial script, here we only finish IPC::Run.
+$psql_session->{run}->finish;
+
+
+#
+# 2. Test of idle in transaction timeout
+#
+
+$node->safe_psql('postgres',
+ "SELECT injection_points_attach('idle-in-transaction-session-timeout', 'wait');");
+
+# We begin a transaction and the hand on the line
+$psql_session =
+ $node->background_psql('postgres');
+$psql_session->query_until(
+ qr/starting_bg_psql/, q(
+ \echo starting_bg_psql
+ SET idle_in_transaction_session_timeout to '10ms';
+ BEGIN;
+));
+
+# Wait until the backend is in the timeout.
+$node->wait_for_event('client backend','idle-in-transaction-session-timeout');
+
+# Remove injection point.
+$node->safe_psql('postgres',
+ "SELECT injection_points_wakeup('idle-in-transaction-session-timeout');");
+ok($psql_session->quit);
+
+
+#
+# 3. Test of idle session timeout
+#
+$node->safe_psql('postgres',
+ "SELECT injection_points_attach('idle-session-timeout', 'wait');");
+
+# We just initialize GUC and wait. No transaction required.
+$psql_session =
+ $node->background_psql('postgres');
+$psql_session->query_until(
+ qr/starting_bg_psql/, q(
+ \echo starting_bg_psql
+ SET idle_session_timeout to '10ms';
+));
+
+# Wait until the backend is in the timeout.
+$node->wait_for_event('client backend','idle-session-timeout');
+
+# Remove injection point.
+$node->safe_psql('postgres',
+ "SELECT injection_points_wakeup('idle-session-timeout');");
+ok($psql_session->quit);
+
+
+# Tests above will hang if injection points are not reached
+ok(1);
+
+done_testing();
--
2.37.1 (Apple Git-137.1)
view thread (61+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Transaction timeout
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox