Mailing List Archive

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

- Log -----------------------------------------------------------------
commit 9c53aadf28d22276ba03a54b35edd6e70696c48e
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 4d940087cb..7ec1e34ace 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2908,6 +2908,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 f942f2957df61f49ed003eee7471b3e2d97ed68d
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..4d940087cb 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -74,6 +74,8 @@ use warnings;
use File::Spec;
use Cwd;

+our $QUERY_TIMEOUT = $ENV{RT_DATABASE_QUERY_TIMEOUT};
+
=head1 METHODS

=head2 FinalizeDatabaseType
@@ -130,11 +132,23 @@ sub Connect {
if ( $db_type eq 'mysql' ) {
# set the character set
$self->dbh->do("SET NAMES 'utf8mb4'");
+ if ( defined $QUERY_TIMEOUT && length $QUERY_TIMEOUT ) {
+ if ( $self->_IsMariaDB ) {
+ $self->dbh->do("SET max_statement_time = $QUERY_TIMEOUT");
+ }
+ else {
+ # max_execution_time is defined in milliseconds
+ $self->dbh->do( "SET max_execution_time = " . int( $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( $QUERY_TIMEOUT * 1000 ) )
+ if defined $QUERY_TIMEOUT && length $QUERY_TIMEOUT;
}

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

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

unless ( $integrity ) {

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


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