]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1461379 - use DBIx::Connector to manage database connections
authorDylan William Hardison <dylan@hardison.net>
Thu, 21 Jun 2018 15:07:50 +0000 (11:07 -0400)
committerGitHub <noreply@github.com>
Thu, 21 Jun 2018 15:07:50 +0000 (11:07 -0400)
.circleci/config.yml
Bugzilla.pm
Bugzilla/DB.pm
Bugzilla/ModPerl.pm
Dockerfile
Makefile.PL
token.cgi

index 341b48062c747d5dd442235de5c9623d513f5cfc..a70ea3ca6849d11c2c7887e63d0bc9728641dcd0 100644 (file)
@@ -7,7 +7,7 @@ version: 2
 
 defaults:
   bmo_slim_image: &bmo_slim_image
-    image: mozillabteam/bmo-slim:20180518.1
+    image: mozillabteam/bmo-slim:20180523.1
     user: app
 
   mysql_image: &mysql_image
index 9df38138dd6388eec6a9578640a3b889d21365c5..427dd3aeaf5047b67ded4e4606182a563e056c3d 100644 (file)
@@ -893,7 +893,6 @@ sub _cleanup {
     foreach my $dbh ($main, $shadow) {
         next if !$dbh;
         $dbh->bz_rollback_transaction() if $dbh->bz_in_transaction;
-        $dbh->disconnect;
     }
     clear_request_cache();
 
index 893c9235ec1c9a09c1700ba909abe937179ced63..33801e9894ebde49524f3a4bd0f397158c28d28d 100644 (file)
@@ -11,6 +11,8 @@ use 5.10.1;
 use Moo;
 
 use DBI;
+use DBIx::Connector;
+our %Connector;
 
 has 'dbh' => (
     is      => 'lazy',
@@ -213,7 +215,6 @@ sub bz_check_server_version {
     my ($self, $db, $output) = @_;
 
     my $sql_vers = $self->bz_server_version;
-    $self->disconnect;
 
     my $sql_want = $db->{db_version};
     my $version_ok = vers_cmp($sql_vers, $sql_want) > -1 ? 1 : 0;
@@ -269,7 +270,6 @@ sub bz_create_database {
         }
     }
 
-    $dbh->disconnect;
 }
 
 # A helper for bz_create_database and bz_check_requirements.
@@ -278,6 +278,7 @@ sub _get_no_db_connection {
     my $dbh;
     my %connect_params = %{ Bugzilla->localconfig };
     $connect_params{db_name} = '';
+    local %Connector = ();
     my $conn_success = eval {
         $dbh = _connect(\%connect_params);
     };
@@ -1261,7 +1262,7 @@ sub _build_dbh {
 
     # set up default attributes used to connect to the database
     # (may be overridden by DB driver implementations)
-    my $attributes = { RaiseError => 0,
+    my $attributes = { RaiseError => 1,
                        AutoCommit => 1,
                        PrintError => 0,
                        ShowErrorStatement => 1,
@@ -1286,17 +1287,9 @@ sub _build_dbh {
         }
     }
 
-    # connect using our known info to the specified db
-    my $dbh = DBI->connect($dsn, $user, $pass, $attributes)
-        or die "\nCan't connect to the database.\nError: $DBI::errstr\n"
-        . "  Is your database installed and up and running?\n  Do you have"
-        . " the correct username and password selected in localconfig?\n\n";
+    my $connector = $Connector{"$user.$dsn"} //= DBIx::Connector->new($dsn, $user, $pass, $attributes);
 
-    # RaiseError was only set to 0 so that we could catch the
-    # above "die" condition.
-    $dbh->{RaiseError} = 1;
-
-    return $dbh;
+    return $connector->dbh;
 }
 
 #####################################################################
index 89eca95853639745c5ec20ce709c3a7af547dc34..19cd1128f2ae269f788af151c0ccf02a842b93fd 100644 (file)
@@ -74,7 +74,7 @@ __DATA__
 # every process, and Perl has another. (Various Perl modules still use
 # the built-in rand(), even though we never use it in Bugzilla itself,
 # so we need to srand() both of them.)
-PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); }"
+PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); eval { Bugzilla->dbh->ping } }"
 PerlInitHandler Bugzilla::ModPerl::Hostage
 PerlAccessHandler Bugzilla::ModPerl::BlockIP
 
index 3ac3209375b32a795ec2b4fecf5198198c4807f0..c86a92b0f195233d701ab17d62120bcd3c3dc033 100644 (file)
@@ -1,4 +1,4 @@
-FROM mozillabteam/bmo-slim:20180518.1
+FROM mozillabteam/bmo-slim:20180523.1
 
 ARG CI
 ARG CIRCLE_SHA1
index 484e66d3d0d06a908197e25eed2a3247387c140b..46228ab5672652983015ba6f58f1e38683bed436 100755 (executable)
@@ -42,6 +42,7 @@ my %requires = (
     'CPAN::Meta::Requirements' => '2.121',
     'Class::XSAccessor'        => '1.18',
     'DBI'                      => '1.614',
+    'DBIx::Connector'          => 0,
     'Data::Password::passwdqc' => '0.08',
     'Date::Format'             => '2.23',
     'DateTime'                 => '0.75',
index 51ed939779c2f82f1bce481adbeb7d93b1e8c58c..99004005071ce42be88884b8f099db8160e5c144 100755 (executable)
--- a/token.cgi
+++ b/token.cgi
@@ -23,7 +23,7 @@ use Date::Format;
 use Date::Parse;
 use JSON qw( decode_json );
 
-my $dbh = Bugzilla->dbh;
+local our $dbh = Bugzilla->dbh;
 local our $cgi = Bugzilla->cgi;
 local our $template = Bugzilla->template;
 local our $vars = {};