jhthorsen / mojo-mysql

Mojolicious and Async MySQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange errors in trace log

AnotherOneAckap opened this issue · comments

I'm trying to use this module, seems to work fine.
But I`m confused with messages in DBI trace log:
!! ERROR: 2000 'Handle is not in asynchronous mode' (err#0)
and then
!! ERROR: 2000 CLEARED by call to fetch method

Could you please explain to me, what happens? is this ok?

It doesn't look to good... Can you provide an example script/test which will provoke this error message?

I'm closing this as wontfix, since I was not able to figure out what this means. Let me know if it actually causes any problems.

@harry-bix: I'm reopening and assigning it to you. You may close it again as wontfix, if you don't get it either.

This is what exactly happens when the gist is executed.

use DBI;
DBI->trace(5);
my $dbh = DBI->connect('dbi:mysql:dbname=test', 'test', '');

my $sth = $dbh->prepare('SELECT * FROM tbl_test WHERE id = 1', { async => 1});
$sth->execute();
while (!$sth->mysql_async_ready) {
}
$sth->mysql_async_result;
# after this point $sth is no longer in async mode
# and call to mysql_async_ready will trigger 2000 'Handle is not in asynchronous mode'
print $sth->fetchrow_hashref->{label};

The call to fetchrow_hashref activates error 2000.
This is becase DBD::mysql calls mysql_async_ready and mysql_async_result for each call to
fetchrow_hashref and fetchall_hashref.
It does not do the same check for fetchrow_arrayref and fetchall_arrayref.

This issue is not directed to the correct project.
If you need a fix comment out lines 854-881 in lib/DBD/mysql.pm of the latest 4.031 version of DBD::mysql.

Thank you for detailed answer, I write to DBD::mysql bug tracker then

Hi, I am one of the DBD::mysql maintainers and I have a hard time making a nice test case out of your issue (or: understanding your issue in the first place).

Please note in the snippet by @harry-bix above, I see print $sth->fetchrow_hashref->{label}; but there should be print $sth->fetchrow_hashref(); or maybe print $sth->fetchall_hashref('label');

I created a test for DBD::mysql which is here:
https://github.com/mbeijen/DBD-mysql/tree/rt103306-async-fetchhashref

You can run this by issuing:

git clone https://github.com/mbeijen/DBD-mysql.git -b rt103306-async-fetchhashref 
cd DBD-mysql
perl Makefile.PL --testuser=foo --testpassword=bar --testdatabase=test
prove -bv t/88async-selects.t 

Please make sure you have libmysqlclient header files installed, this is typically found in the linux package libmysqlclient-dev.

You'll see the tests succeed. Please help me understand the issue!

Hi, @mbeijen

You will see:

       ERROR: 2000 'Handle is not in asynchronous mode' (err#0)
...
    !! The ERROR '2000' was CLEARED by call to bind_columns method

if you enable DBI->trace(1) in t/88async-selects.t
Obviously the error is not-fatal and all test pass.

In the example I've submitted 'label' is a column name. The error 2000 also appears only if trace is enabled and is also non-fatal.

Lines 858-869 in lib/DBD/mysql.pm seem to allow to call fetchrow_hashref or fetchall_hashref while the handle is in async mode.
Why not for fetchrow_arrayref or fetchall_arrayref.
Why should be possible to call fetch before ensuring async result is ready.
Why is the whole BEGIN (line 854-881) needed.

Has this been patched in DBD::mysql? I'm getting this error as well. Harry-bix -- great work on finding this esoteric situation.

Ah! Thanks for reminding me. No, it has not yet been fixed, yes, pull requests are welcome!

https://github.com/perl5-dbi/DBD-mysql/