-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ping() on disconnected db handles #306
Comments
Implicit reconnection is definitely a bad idea! |
@dveeden there is a configuration already to enable this behavior mysql_auto_reconnect which is highly discouraged because it is bad to have a handle reconnect while you think you are in a transaction, or have table locks, or other session state that would be lost when reconnecting. This should not be done without this option set! |
Hi. Is there any reason why a implicit reconnect was implemented in version 4.050? Can't find any change documentation / requirements. |
Yes there was a reason to do that, but I don't recall the exact reason from the top of my head. However with |
This causes a segfault with mariadb versions 10.3 and higher, if you call ping after disconnect. use Test::More; say "please provide db name"; done_testing(); |
I've been able to implement a workaround where disconnect is wrapped in a sub, and a flag set if the database version contains mariadb and version is 10.3 or higher, then checking that flag and forcing reconnect without calling ping if that flag is set (and unsetting the flag on successful connection) |
Hello, just to note that |
Hi Pali, no DBD::MariaDB does not fix the ping following disconnect segfault. I've replicated it on debian buster and stretch with both DBD::MariaDB and DBD::mysql against MariaDB 10.3 and 10.4 - both needed the workaround |
@hashbangperl if there is still segfault with DBD::MariaDB please report it to our project https://github.com/gooddata/DBD-MariaDB/issues and we look at it... but it is strange as I was testing specially this problem against 10.3 and there was no crash anymore. |
created issue. yeah, I got the problem between 1 in 2 and 1 in 4 times when running, and with the autoreconnect flag set. |
I've managed to trigger a segfault inside gdb with mysql dbd against mariadb, using the test above. gdb -ex r -ex bt -ex quit --args perl mariadb_disconnect_bug.t For help, type "help". Program received signal SIGSEGV, Segmentation fault.
|
added PR with extra tests, which should fail if using mariadb 10.3 or newer server that's under load. #319 |
We call ping on existing dbh to check if it's still active or not, which sadly could cause segmentation faults on mariadb 10.3+, related code is in both Connect and TransactionDepth methods: $self->dbh && $self->dbh->ping Here we unset dbh to get around the issue. A couple of more notes: * Not just ping, SQL queries also have this issue. Thus we can't change ping to a light query like "SELECT VERSION()" * It happens only on an *explicitly* disconnected handle There is no such issue for indirect disconnects like restarting database server or killing connection processes. See also perl5-dbi/DBD-mysql#306
We call ping on existing dbh to check if it's still active or not, which sadly could cause segmentation faults on mariadb 10.2+, related code is in both Connect and TransactionDepth methods: $self->dbh && $self->dbh->ping Here we unset dbh to get around the issue. A couple of more notes: * Not just ping, SQL queries also have this issue. Thus we can't change ping to a light query like "SELECT VERSION()" * It happens only on an *explicitly* disconnected handle There is no such issue for indirect disconnects like restarting database server or killing connection processes. See also perl5-dbi/DBD-mysql#306
Hi, all, I've had a chance to look at this briefly. Here is where the code is segfaulting in mariadb_lib.c:
I believe the error is in mysql_close in mariadb_lib.c. Have a look at this code:
mysql_close frees msyql->net.extension and mysql->extension, but does NOT set them to NULL. So they're pointing to freed memory and when they are reused... SEGV. I will try and patch mariadb_lib.c to see if my theory is correct and if I can fix it. Regards, Dianne. |
This patch to the MariaDB client library seems to fix the problem. |
I believe the patch that caused this needs to be reverted and implemented properly. Currently, the workaround to return the previous behavior is to use AutoCommit = 0. This is absolutely wrong, and the said patch should check mysql_auto_reconnect instead. |
- Updated test t/lib/TableChecksum.t so it reflects changes, introduced in the fix for PT-2016 - Updated test t/lib/RowChecksum.t so it reflects changes added to in the fix for PT-2138: UTF8 support - Uncommented SQL in sandbox/slave_channels.sql that made t/lib/MasterSlave.t to fail - Added check for undef into t/pt-archiver/archive_using_channels.t - Updated lib/Cxn.pm so it uses $dbh->{Active} after issue with the ping() call, reported at perl5-dbi/DBD-mysql#306
- Impoved the fix for PT-2016, so it does not files with keys with USING keyword - Added brackets to expression in lib/TableNibbler.pm, so it does not crap query wit many indexes with OR keyword - Adjusted test t/lib/TableNibbler.t, so it reflects above chages - Modified lib/Cxn.pm, so it has workaround for perl5-dbi/DBD-mysql#306 , introduced in DBD::mysql 4.0.50 - Updated tests: added debugging code and cleanups - Updated modules for tools
* PT-2156 - Fix tests for lib - Fixed tests broken for lib/TableParser.pm after fix for PT-1059 - Updated tests for lib/TableParser.pm that are broken due to SHOW CREATE TABLE output format change in 8.0 - Updated modules for all tools that use lib/TableParser.pm * Revert "Fixed pt-archiver tests" This reverts commit a3ab87b. This commit wa needed, because removed code in sandbox/slave_channels.sql broked the test. Proper fix would be to do not remove channel names rather than chaging the test. So revertig it. * PT-2156 - Fix tests for lib - Updated test t/lib/TableChecksum.t so it reflects changes, introduced in the fix for PT-2016 - Updated test t/lib/RowChecksum.t so it reflects changes added to in the fix for PT-2138: UTF8 support - Uncommented SQL in sandbox/slave_channels.sql that made t/lib/MasterSlave.t to fail - Added check for undef into t/pt-archiver/archive_using_channels.t - Updated lib/Cxn.pm so it uses $dbh->{Active} after issue with the ping() call, reported at perl5-dbi/DBD-mysql#306 * PT-2156 - Fix tests for lib - Impoved the fix for PT-2016, so it does not files with keys with USING keyword - Added brackets to expression in lib/TableNibbler.pm, so it does not crap query wit many indexes with OR keyword - Adjusted test t/lib/TableNibbler.t, so it reflects above chages - Modified lib/Cxn.pm, so it has workaround for perl5-dbi/DBD-mysql#306 , introduced in DBD::mysql 4.0.50 - Updated tests: added debugging code and cleanups - Updated modules for tools
With the latest version of
DBD::mysql
one of my testcases is failing. The testcase is basically just doing thisWe tracked this behaviour down to the commit 998cd6a, which is reopening a diconnected DBH.
The POD of
DBI
for ping says:I am not perfectly sure but i would argue that ping should not reopen the connection.
The text was updated successfully, but these errors were encountered: