CurtTilmes / perl6-dbmysql

DB::MySQL
2 stars 3 forks source link

Segmentation fault on releasing resources with finish() #9

Open migotom opened 4 years ago

migotom commented 4 years ago

Simple prepare statement crashes with segmentation fault when using finish() on simple single row result:

#!/usr/bin/env perl6

use v6;

use DB::MySQL;
use lib 'lib';

my $dbh = DB::MySQL.new( 
        host => "dbhost",
        database => "db",
        port => 3306,
        user => "user",
        password => "password"
    ).db;

loop {
    my $query = "SELECT * FROM users";
    my $sth = $dbh.prepare($query);
    my @rows = $sth.execute().array;
    $sth.finish();
}
$dbh.finish;

Execution result:

backend$ perl6 t/stability_mysql.t6
Segmentation fault

DB schema:

CREATE TABLE `users` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `login` varchar(128) NOT NULL,
  `password` varchar(64) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `login` (`login`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='' 
bbkr commented 4 years ago

More simple case (without need of db tables):

loop {
    my $query = 'SELECT 1 FROM dual';
    my $sth = $dbh.prepare($query);
    my @rows = $sth.execute().array;
    say 'OK';
}

gives crash after random time:

OK
OK
OK
OK
OK
OK
OK
Cannot look up attributes in a DB::MySQL::Native::ResultsBind type object
  in method AT-POS at ~/perl6/site/sources/95C0806CA001A1EB28D0FC597A2FE4FF5195D52C (DB::MySQL::Native) line 146
  in code  at ~/perl6/site/sources/507086ECAA98656966E41BC1EE8B998728F2C615 (DB::MySQL::Result) line 71
  in method row at ~/perl6/site/sources/507086ECAA98656966E41BC1EE8B998728F2C615 (DB::MySQL::Result) line 69
  in method free at ~/perl6/site/sources/507086ECAA98656966E41BC1EE8B998728F2C615 (DB::MySQL::Result) line 44
  in submethod DESTROY at ~/perl6/site/sources/51F6397FB5D02B2A0E15A62EC3ACF47669DBF3DC (DB::Result) line 83
  in method make-buffer at ~/perl6/site/sources/715B7B691EFB5DDF0C875852F7F436F293969520 (DB::MySQL::Converter) line 261
  in submethod TWEAK at ~/perl6/site/sources/507086ECAA98656966E41BC1EE8B998728F2C615 (DB::MySQL::Result) line 59
  in method execute at ~/perl6/site/sources/B7FEB638A8625E3D92CB2064EB9B456EA2C69806 (DB::MySQL::Statement) line 43
  in block <unit> at test.pl line 1
bbkr commented 4 years ago

BTW: Does StatementResult::free method needs to exhaust rows with full type conversion? This looks very inefficient.

CurtTilmes commented 4 years ago

I can replicate the problem, but haven't found a fix -- I'll try to go through it later. I have to re-learn MySQL's API.. It has been a while since I've looked at this.

bbkr commented 4 years ago

Hi. Do you have any ETA about this bug? Module is unusable because of it.

Thanks.

leobm commented 2 years ago

have the same problem