[Rt-commit] rt branch 5.0/statement-timeout created. rt-5.0.3-146-gb338f13b37
BPS Git Server
git at git.bestpractical.com
Tue Dec 6 22:03:17 UTC 2022
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 b338f13b3769a6ee38b43acfc4cfc4f84a8013c2 (commit)
- Log -----------------------------------------------------------------
commit b338f13b3769a6ee38b43acfc4cfc4f84a8013c2
Author: sunnavy <sunnavy at 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/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index da6382ec27..45aae2af2c 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -422,6 +422,8 @@ sub HandleRequest {
Path => $HTML::Mason::Commands::m->request_path,
});
+ $HTML::Mason::Commands::m->comp( '/Elements/End', %$ARGS );
+
# Process per-page final cleanup callbacks
$HTML::Mason::Commands::m->callback( %$ARGS, CallbackName => 'Final', CallbackPage => '/autohandler' );
diff --git a/share/html/Elements/End b/share/html/Elements/End
new file mode 100644
index 0000000000..ba1c64cd45
--- /dev/null
+++ b/share/html/Elements/End
@@ -0,0 +1,54 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+% 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>
+% }
commit 68a43efcfea2943ffef0ff5783a500510066ab5f
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Nov 17 06:01:28 2022 +0800
Add $DatabaseQueryTimeout to abort long running SQL queries
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index bd9c001d28..98d067857d 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -281,6 +281,24 @@ during upgrades.
Set($DatabaseAdmin, "@DB_DBA@");
+=item C<$DatabaseQueryTimeout>
+
+Time in seconds to allow a single database query to run before
+timing out. This helps prevent performance penalties for expensive,
+long-running queries. This value, if set, should be less than any
+timeout settings in your web server (Apache, etc.) so the user can
+receive a message rather than a server timeout error.
+
+It's disabled by default and only works with MariaDB/MySQL/PostgreSQL.
+
+If you have command-line scripts that may require a longer-running query,
+you can set the environment variable C<RT_DATABASE_QUERY_TIMEOUT>
+to override the value set in RT's configuration.
+
+=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
More information about the rt-commit
mailing list