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

? sunnavy sunnavy at bestpractical.com
Wed Jul 1 13:32:13 EDT 2020


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

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

    Fix segmentation faults on reconnect for mariadb 10.2+
    
    We call ping on existing dbh to check if it's still active or not, which
    sadly could cause segmentation faults on mariadb 10.2+, 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..d0f67fc 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.2+ 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.2' )
+    {
+        $self->dbh(undef);
+    }
+
+    return $ret;
+}
 
 
 =head2 dbh [HANDLE]

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


More information about the Bps-public-commit mailing list