Subject: | DBD::SQLite::db do failed: database is locked |
The test suite fails on my FreeBSD smokers:
...
DBD::SQLite::db do failed: database is locked at t/Dancer2-Session-DatabasePlugin.t line 161.
[Test::Session:66183] error @2018-06-24 01:00:31> Route exception: DBD::SQLite::db do failed: database is locked at t/Dancer2-Session-DatabasePlugin.t line 161. in /usr/perl5.26.0p/lib/site_perl/5.26.0/Dancer2/Core/App.pm l. 1473
# Failed test 'Should get a 200'
# at t/Dancer2-Session-DatabasePlugin.t line 44.
# got: 500
# expected: 200
DBD::SQLite::db prepare failed: database is locked at /home/cpansand/.cpan/build/2018062400/Dancer2-Session-DatabasePlugin-1.0001-2/blib/lib/Dancer2/Session/DatabasePlugin.pm line 250.
[Test::Session:66183] error @2018-06-24 01:00:31> Route exception: Unable to create a new session: DBD::SQLite::db prepare failed: database is locked at /home/cpansand/.cpan/build/2018062400/Dancer2-Session-DatabasePlugin-1.0001-2/blib/lib/Dancer2/Session/DatabasePlugin.pm line 250.
at /usr/perl5.26.0p/lib/site_perl/5.26.0/Dancer2/Core/App.pm line 455. in /usr/perl5.26.0p/lib/site_perl/5.26.0/Dancer2/Core/App.pm l. 1473
# Failed test 'Should get a 200'
# at t/Dancer2-Session-DatabasePlugin.t line 58.
# got: 500
# expected: 200
# Failed test 'Should have a cookie!'
# at t/Dancer2-Session-DatabasePlugin.t line 59.
# Failed test 'Should have more than 0 statement handles'
# at t/Dancer2-Session-DatabasePlugin.t line 60.
# '0'
# >
# '0'
# Failed test 'Should have a cookie!'
# at t/Dancer2-Session-DatabasePlugin.t line 67.
# Failed test at t/Dancer2-Session-DatabasePlugin.t line 68.
# got: ''
# expected: 'I am a little teapot.'
# Failed test 'Should have more than 0 statement handles'
# at t/Dancer2-Session-DatabasePlugin.t line 69.
# '0'
# >
# '0'
[Test::Session:66183] debug @2018-06-24 01:00:31> Database connection went away, reconnecting in /usr/perl5.26.0p/lib/site_perl/5.26.0/Dancer2/Plugin.pm l. 543
DBD::SQLite::db selectall_arrayref failed: database is locked at t/Dancer2-Session-DatabasePlugin.t line 76.
DBD::SQLite::db selectall_arrayref failed: database is locked at t/Dancer2-Session-DatabasePlugin.t line 76.
# Looks like your test exited with 35 just after 22.
t/Dancer2-Session-DatabasePlugin.t ..
Dubious, test returned 35 (wstat 8960, 0x2300)
Failed 7/22 subtests
...
The problem is caused by both tempfile() (only on BSD systems) and sqlite setting a lock on the database file. This can be fixed by setting EXLOCK => 0:
our $DB;
our $FH;
BEGIN {
($FH,$DB)=tempfile(EXLOCK=>0);
}
See also https://rt.cpan.org/Ticket/Display.html?id=123959 for a discussion about EXLOCK in File::Temp.