Skip to content
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

Enable auto reconnect for ER_CLIENT_INTERACTION_TIMEOUT #383

Merged
merged 1 commit into from Nov 3, 2023

Conversation

dveeden
Copy link
Collaborator

@dveeden dveeden commented Nov 1, 2023

Previously waiting for more than the wait_timeout would result in CR_SERVER_LOST, but now the server tries to notify the client about the reason it was disconnected and this results in a different error.

Closes #162

See also:

#!/bin/perl
use v5.36;
use DBI;
use Data::Dumper;


my $dbh = DBI->connect('DBI:mysql:database=test', 'root', 'Root123@', {
    mysql_auto_reconnect => 1,
    RaiseError => 1,
    AutoCommit => 1,
});

my $res = $dbh->selectall_arrayref("SELECT CONNECTION_ID()");
say "Connection ID: " . @$res[0]->[0];
say "Stats:\n- auto_reconnects_ok=" . $dbh->{mysql_dbd_stats}->{auto_reconnects_ok};
say "- auto_reconnects_failed=" . $dbh->{mysql_dbd_stats}->{auto_reconnects_failed};

$dbh->do("SET SESSION wait_timeout=3");
sleep(4);

$res = $dbh->selectall_arrayref("SELECT CONNECTION_ID()");
say "Connection ID: " . @$res[0]->[0];
say "Stats:\n- auto_reconnects_ok=" . $dbh->{mysql_dbd_stats}->{auto_reconnects_ok};
say "- auto_reconnects_failed=" . $dbh->{mysql_dbd_stats}->{auto_reconnects_failed};

$dbh->do("ROLLBACK RELEASE");

$res = $dbh->selectall_arrayref("SELECT CONNECTION_ID()");
say "Connection ID: " . @$res[0]->[0];
say "Stats:\n- auto_reconnects_ok=" . $dbh->{mysql_dbd_stats}->{auto_reconnects_ok};
say "- auto_reconnects_failed=" . $dbh->{mysql_dbd_stats}->{auto_reconnects_failed};
$ ~/reconnect.pl 
Connection ID: 425
Stats:
- auto_reconnects_ok=0
- auto_reconnects_failed=0
Connection ID: 426
Stats:
- auto_reconnects_ok=1
- auto_reconnects_failed=0
Connection ID: 427
Stats:
- auto_reconnects_ok=2
- auto_reconnects_failed=0

@dveeden dveeden merged commit b5d72db into perl5-dbi:master Nov 3, 2023
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mysql_auto_reconnect not working any more [rt.cpan.org #93387]
1 participant