on_error issue with AnyEvent::DBI
Winfried Neessen
wn at neessen.net
Sat Feb 1 20:50:18 CET 2020
Hi,
I am currently trying to implement AnyEvent::DBI into the code I am writing. While intentionally providing wrong
connection data to my PgSQL database, to test the on_error behaviour I ran into an issue. The provided on_error
callback is not executed, as the _error method in AnyEvent/DBI.pm dies before the actual call of the self provided
callback is issues. I narrowed the issue down to line 349 of DBI.pm:
346 # for fatal errors call all enqueued callbacks with error
347 while (my $req = shift @{$self->{queue}}) {
348 local $@ = $error;
349 $req->[0]->($self);
350 }
Once the $req->[0]->($self); is executed, the "die" of the DBI->connect() will be executed and the script will not
do any further action (like executing the self-provided "$self->{on_error}($self, $filename, $line, $fatal)" in line
357.
Unfortunately my knowledge of AnyEvent is not good enough to understand what is actually happening in line
349.
I am running Perl 5.30.1 on FreeBSD 12.1-RELEASE-p2. Modul versions are:
- AnyEvent 7.17
- AnyEvent::DBI 3.04
- DBI 1.643
- DBD::Pg 3.10.3
My code to construct the AnyEvent::DBI class is:
47 $self->mainLoop->begin;
48 my $dbObj = AnyEvent::DBI->new(
49 'DBI:' . $self->confObj->param('database.db_type') .
50 ':dbname=' . $self->confObj->param('database.db_name') .
51 ';host=' . $self->confObj->param('database.db_host'),
52 $self->confObj->param('database.db_user'),
53 $self->confObj->param('database.db_pass'),
54 AutoCommit => 0,
55 PrintError => 1,
56 RaiseError => 0,
57 on_connect => sub {
58 my (undef, $isSuccess) = @_;
59 if(!defined($isSuccess)) {
60 return $self->logObj->error('Connection to database was not successful.');
61 }
62 },
63 on_error => sub {
64 my ($dbh, $filename, $line, $fatal) = @_;
65 print Dumper $fatal;
66 $self->logObj->error('DBI Error: ' . $@ . ' at ' . $_[1] . ':' . $_[2]);
67 },
68
69 );
Any idea why this is happening? I really need to my own on_error, as I don't want my AnyEvent loop to
die just because the DB might not be available or the connection string might be not correct.
Any help is highly appreciated.
Winni
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20200201/593695ce/attachment.sig>
More information about the anyevent
mailing list