[Dancer-users] dbh->ping causes segmentation fault in D::P::Database

Иван Бессарабов ivan at bessarabov.ru
Sat Dec 4 12:20:58 CET 2010


The only thing that stopped me from using dancer in production is the
problem that it accidently crashes.
Today and yesterday I was experimenting to find out the problem. I
have found the solution that fixes the problem, but maybe somebody can
find better solution.

So. How to reproduce the problem.

perl, v5.10.1
Dancer v1.2000
Dancer::Plugin::Database v0.11
DBI v1.615
DBD::mysql v4.007
mysql  Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1

Then create simple application ("dancer -a MyDb") in config write db
connection info:
plugins:
    Database:
        driver: 'mysql'
        database: 'sample'
        host: 'localhost'
        username: 'uname'
        password: 'secret'
        connection_check_threshold: 1
        dbi_params:
            RaiseError: 1
            AutoCommit: 1
        on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]

In MyDb.pm write something like:
    my $sth = database->prepare('SELECT count(id) AS c FROM t1');
    $sth->execute;
    $v->{count} = $sth->fetchrow_hashref->{c};

Then start app by "./bin/app.pl", access the page, then restart mysql
and try to access the same route again. The app is not responding and
in log I get this:

[16248]  core @0.028376> [hit #8] trying to match `/' against /^\/$/
in /usr/local/share/perl/5.10.1/Dancer/Route.pm l. 74
[16248]  core @0.028638> [hit #8]   --> got 1 in
/usr/local/share/perl/5.10.1/Dancer/Route.pm l. 80
./start: line 1: 16248 Segmentation fault      ./bin/app.pl

After investigating I have found that the app is crashed by line "my
$result = $dbh->ping" in Dancer/Plugin/Database.pm

In the internet I have found the solution
http://www.nntp.perl.org/group/perl.dbi.users/2008/07/msg33044.html

I've added one line to my config file and it stopped crashing. Here is
the fragment of config.yml that works without crahses:

        dbi_params:
            mysql_auto_reconnect: 0
            RaiseError: 1
            AutoCommit: 1


More information about the Dancer-users mailing list