[Bps-public-commit] dbix-searchbuilder branch, fix-mariadb-reconnect-segfaults, created. 1.67-4-ge972539

? sunnavy sunnavy at bestpractical.com
Tue Jun 30 18:38:02 EDT 2020


The branch, fix-mariadb-reconnect-segfaults has been created
        at  e972539b66af20136f3d27537c8c84e897d4e571 (commit)

- Log -----------------------------------------------------------------
commit e972539b66af20136f3d27537c8c84e897d4e571
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jul 1 06:17:20 2020 +0800

    Fix segmentation faults for mariadb 10.3+ on reconnect
    
    We call ping on existing dbh to check if it's still active or not, which
    sadly could cause segmentation faults on mariadb 10.3+, related code is
    in both Connect and TransactionDepth methods:
    
        $self->dbh && $self->dbh->ping
    
    Here we unset dbh to get around the issue.
    
    A couple of more notes:
    
    * Not just ping, SQL queries also have this issue.
    
    Thus we can't change ping to a light query like "SELECT VERSION()"
    
    * It happens only on an *explicitly* disconnected handle
    
    There is no such issue for indirect disconnects like restarting database
    server or killing connection processes.
    
    See also https://github.com/perl5-dbi/DBD-mysql/issues/306

diff --git a/lib/DBIx/SearchBuilder/Handle.pm b/lib/DBIx/SearchBuilder/Handle.pm
index bba90b3..f7b02df 100755
--- a/lib/DBIx/SearchBuilder/Handle.pm
+++ b/lib/DBIx/SearchBuilder/Handle.pm
@@ -113,6 +113,9 @@ sub Connect  {
     # Set the handle
     $self->dbh($handle);
 
+    # Cache version info
+    $self->DatabaseVersion;
+
     return 1;
 }
 
@@ -309,9 +312,23 @@ sub Disconnect  {
     my $dbh = $self->dbh;
     return unless $dbh;
     $self->Rollback(1);
-    return $dbh->disconnect;
-}
 
+    my $ret = $dbh->disconnect;
+
+    # DBD::mysql with MariaDB 10.3+ could cause segment faults when
+    # interacting with a disconnected handle, here we unset
+    # dbh to inform other code that there is no connection any more.
+    # See also https://github.com/perl5-dbi/DBD-mysql/issues/306
+
+    if (   $self->isa('DBIx::SearchBuilder::Handle::mysql')
+        && $self->{'database_version'} =~ /mariadb/i
+        && $self->{'database_version'} ge '10.3' )
+    {
+        $self->dbh(undef);
+    }
+
+    return $ret;
+}
 
 
 =head2 dbh [HANDLE]

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


More information about the Bps-public-commit mailing list