Subject: | potential bug with transactions / locking |
Date: | Thu, 21 May 2009 14:33:29 -0600 (MDT) |
To: | bug-dbd-sqlite [...] rt.cpan.org |
From: | "Steve K. Hurst" <skhurst [...] clusterresources.com> |
Hi!
I think I've encountered a bug in DBD::SQLite that allows a second process to try and access the db when another is in a transaction. It occurs when I have something like:
begin
write write write ... fetch ... write ...
commit
the 'fetch' inside the transaction seems to be what provokes the problem.
The smallest code I found that recreates the problem (child dies with db locked error):
#!/usr/bin/perl -w
use strict;
my $pid = fork();
if ( $pid )
{
# parent
write_db();
}
elsif ( defined $pid )
{
# child
sleep 1;
write_db();
exit(0);
}
waitpid($pid, 0);
exit(0);
sub write_db
{
require DBI;
require DBD::SQLite;
my $dbh = DBI->connect("dbi:SQLite:dbname=test.db","","");
$dbh->{RaiseError} = 1;
$dbh->do('CREATE TABLE IF NOT EXISTS test (id text,text text)');
$dbh->do('CREATE TABLE IF NOT EXISTS test2 (id2 text,text2 text)');
$dbh->begin_work();
# comment the select, and I no longer break
$dbh->do('SELECT * from test2');
$dbh->do("INSERT INTO test VALUES ($$, 'this is a test')");
sleep 2;
$dbh->commit();
}