Mailing List Archive

rt branch 5.0/statement-timeout created. rt-5.0.3-146-g66492ac1d8
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/statement-timeout has been created
at 66492ac1d8920285c8e743aa985e7cbaff366d22 (commit)

- Log -----------------------------------------------------------------
commit 66492ac1d8920285c8e743aa985e7cbaff366d22
Author: sunnavy <sunnavy@bestpractical.com>
Date: Wed Nov 23 05:42:01 2022 +0800

Show end users a hint about SQL error

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 39a9079996..318adfc7f3 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2906,6 +2906,18 @@ sub _CanonilizeObjectCustomFieldValue {
}
}

+sub SimpleQuery {
+ my $self = shift;
+ my $ret = $self->SUPER::SimpleQuery(@_);
+ return $ret if $ret;
+
+ # Show end user something if query failed.
+ if ($HTML::Mason::Commands::m) {
+ $HTML::Mason::Commands::m->notes( 'SQLError' => 1 );
+ }
+ return $ret;
+}
+
__PACKAGE__->FinalizeDatabaseType;

RT::Base->_ImportOverlays();
diff --git a/share/html/Elements/Footer b/share/html/Elements/Footer
index 556efcc950..ee89f30470 100644
--- a/share/html/Elements/Footer
+++ b/share/html/Elements/Footer
@@ -78,6 +78,13 @@
</pre>
% }
</div>
+% if ( $m->notes('SQLError') ) {
+<script type="text/javascript">
+jQuery( function() {
+ jQuery.jGrowl(<% loc('Page content might be inaccurate because of SQL error. Please contact your admin, they can find more details in the logs.') |j %>, { sticky: true, themeState: 'none' });
+} );
+</script>
+% }
</body>
</html>
<%ARGS>

commit 31ab4292158917f23c6f371d32f8e4dd8bc1e420
Author: sunnavy <sunnavy@bestpractical.com>
Date: Thu Nov 17 06:01:28 2022 +0800

Add config $StatementTimeout to abort long running SQL queries from web ui

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index bd9c001d28..702113a882 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -281,6 +281,20 @@ during upgrades.

Set($DatabaseAdmin, "@DB_DBA@");

+=item C<$DatabaseQueryTimeout>
+
+Time in seconds before a SQL statement times out. This is to abort
+long running SQL that can cause performance penality.
+
+It's disabled by default.
+
+Note that this affects RT web service only and only works with
+MariaDB/MySQL/PostgreSQL.
+
+=cut
+
+Set($DatabaseQueryTimeout, undef);
+
=back


diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index b659fbc291..bd5cadb143 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1894,6 +1894,10 @@ our %META;
DashboardSubject => {
Widget => '/Widgets/Form/String',
},
+ DatabaseQueryTimeout => {
+ Immutable => 1,
+ Widget => '/Widgets/Form/String',
+ },
DefaultErrorMailPrecedence => {
Widget => '/Widgets/Form/String',
},
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index f557832669..39a9079996 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -130,11 +130,23 @@ sub Connect {
if ( $db_type eq 'mysql' ) {
# set the character set
$self->dbh->do("SET NAMES 'utf8mb4'");
+ if ( defined $ENV{RT_DATABASE_QUERY_TIMEOUT} && length $ENV{RT_DATABASE_QUERY_TIMEOUT} ) {
+ if ( $self->_IsMariaDB ) {
+ $self->dbh->do("SET max_statement_time = $ENV{RT_DATABASE_QUERY_TIMEOUT}");
+ }
+ else {
+ # max_execution_time is defined in milliseconds
+ $self->dbh->do( "SET max_execution_time = " . int( $ENV{RT_DATABASE_QUERY_TIMEOUT} * 1000 ) );
+ }
+ }
}
elsif ( $db_type eq 'Pg' ) {
my $version = $self->DatabaseVersion;
($version) = $version =~ /^(\d+\.\d+)/;
$self->dbh->do("SET bytea_output = 'escape'") if $version >= 9.0;
+ # statement_timeout is defined in milliseconds
+ $self->dbh->do( "SET statement_timeout = " . int( $ENV{RT_DATABASE_QUERY_TIMEOUT} * 1000 ) )
+ if defined $ENV{RT_DATABASE_QUERY_TIMEOUT} && length $ENV{RT_DATABASE_QUERY_TIMEOUT};
}

$self->dbh->{'LongReadLen'} = RT->Config->Get('MaxAttachmentSize');
diff --git a/sbin/rt-server.in b/sbin/rt-server.in
index 871b66c6c8..b17a9880b3 100644
--- a/sbin/rt-server.in
+++ b/sbin/rt-server.in
@@ -91,6 +91,8 @@ RT->LoadConfig();
RT->InitPluginPaths();
RT->InitLogging();

+$ENV{RT_DATABASE_QUERY_TIMEOUT} //= RT->Config->Get('DatabaseQueryTimeout');
+
require RT::Handle;
my ($integrity, $state, $msg) = RT::Handle->CheckIntegrity;


-----------------------------------------------------------------------


hooks/post-receive
--
rt
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
https://lists.bestpractical.com/mailman/listinfo/rt-commit