Subject: | Reconnection does not work if timeout occurs in a transaction |
Reconnection does not work if timeout occurs in a transaction.
my-script.pl
use feature 'say';
use My::Schema;
my $schema = My::Schema->connect('dbi:mysql:host=127.0.0.1;port=3306;database=test;mysql_write_timeout=1;mysql_read_timeout=1', 'root', '');
my $user_rs = $schema->resultset('User');
say 'transaction_depth = ', $schema->storage->{transaction_depth}; # => transaction_depth = 0
eval {
my $txn = $schema->txn_scope_guard;
say 'transaction_depth = ', $schema->storage->{transaction_depth}; # => transaction_depth = 1
# timeout
$user_rs->search({}, {select => \'SLEEP(10)'})->all;
}
# I expect that transaction_depth is 0, but transaction_depth is 1 actually.
say 'transaction_depth = ', $schema->storage->{transaction_depth}; # => transaction_depth = 1
# I expect that DBIx::Class reconnects to MySQL,
# but this code dies with "MySQL server has gone away" actually.
$user_rs->search({ id => 1 })->single;
User.pm
package My::Schema::User;
use base 'DBIx::Class::Core';
__PACKAGE__->table('user');
__PACKAGE__->add_columns(
id => {
data_type => 'INTEGER',
is_nullable => 0,
is_auto_increment => 1,
},
username => {
data_type => 'VARCHAR',
size => 255,
is_nullable => 0,
},
);
__PACKAGE__->set_primary_key('id');
1;
Schema.pm
package My::Schema;
use base 'DBIx::Class::Schema';
__PACKAGE__-> load_namespaces;
1;
My environment is:
- DBIx::Class version 0.082820.
- This is perl 5, version 20, subversion 2 (v5.20.2) built for x86_64-linux
- CentOS release 6.6 (Final)