Mailing List Archive

rt branch 5.0/statement-timeout created. rt-5.0.3-146-ge855116d70
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 e855116d703082a8d7cf509a2efed9fb8b05de78 (commit)

- Log -----------------------------------------------------------------
commit e855116d703082a8d7cf509a2efed9fb8b05de78
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 6f29cb2856..2c06b49972 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2907,6 +2907,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 3800407f7f6ce26bf728c250c3401d355655cbcb
Author: sunnavy <sunnavy@bestpractical.com>
Date: Thu Nov 17 06:01:28 2022 +0800

Add config $StatementTimeout to abort long running SQL queries

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index bd9c001d28..f45c360116 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 and only works with MariaDB/MySQL/PostgreSQL.
+
+You can also set environment's C<RT_DATABASE_QUERY_TIMEOUT> variable to
+override the value.
+
+=cut
+
+Set($DatabaseQueryTimeout, undef);
+
=back


diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index b659fbc291..5f8156ac57 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1894,6 +1894,19 @@ our %META;
DashboardSubject => {
Widget => '/Widgets/Form/String',
},
+ DatabaseQueryTimeout => {
+ Immutable => 1,
+ Widget => '/Widgets/Form/String',
+ PostLoadCheck => sub {
+ my $self = shift;
+ if ( defined $ENV{RT_DATABASE_QUERY_TIMEOUT} && length $ENV{RT_DATABASE_QUERY_TIMEOUT} ) {
+ RT->Logger->debug(
+ "Env RT_DATABASE_QUERY_TIMEOUT is defined, setting DatabaseQueryTimeout to '$ENV{RT_DATABASE_QUERY_TIMEOUT}'."
+ );
+ $self->Set('DatabaseQueryTimeout', $ENV{RT_DATABASE_QUERY_TIMEOUT} );
+ }
+ },
+ },
DefaultErrorMailPrecedence => {
Widget => '/Widgets/Form/String',
},
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index f557832669..6f29cb2856 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -127,14 +127,27 @@ sub Connect {
%args,
);

+ my $timeout = RT->Config->Get('DatabaseQueryTimeout');
if ( $db_type eq 'mysql' ) {
# set the character set
$self->dbh->do("SET NAMES 'utf8mb4'");
+ if ( defined $timeout && length $timeout ) {
+ if ( $self->_IsMariaDB ) {
+ $self->dbh->do("SET max_statement_time = $timeout");
+ }
+ else {
+ # max_execution_time is defined in milliseconds
+ $self->dbh->do( "SET max_execution_time = " . int( $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( $timeout * 1000 ) )
+ if defined $timeout && length $timeout;
}

$self->dbh->{'LongReadLen'} = RT->Config->Get('MaxAttachmentSize');

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


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