Skip to content

Commit 65a80d2

Browse files
palichoroba
authored andcommitted
Fix mariadb_auto_reconnect for MySQL 8.0.24+
MySQL server version 8.0.24 started returning new error code ER_CLIENT_INTERACTION_TIMEOUT for timeout disconnect reason. Fix mariadb_auto_reconnect to handle this new code and extend t/15reconnect.t test for timeout disconnect reason via changing wait_timeout. See: https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-24.html#mysqld-8-0-24-connection-management See: https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_client_interaction_timeout
1 parent f80b3b9 commit 65a80d2

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

dbdimp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ IV mariadb_db_do6(SV *dbh, imp_dbh_t *imp_dbh, SV *statement_sv, SV *attribs, I3
28342834
#endif
28352835
/* This is error for previous unfetched result ret. So do not report server errors to caller which is expecting new result set. */
28362836
error = mysql_errno(imp_dbh->pmysql);
2837-
if (error == CR_COMMANDS_OUT_OF_SYNC || error == CR_OUT_OF_MEMORY || error == CR_SERVER_GONE_ERROR || error == CR_SERVER_LOST || error == CR_UNKNOWN_ERROR)
2837+
if (error == CR_COMMANDS_OUT_OF_SYNC || error == CR_OUT_OF_MEMORY || error == CR_SERVER_GONE_ERROR || error == CR_SERVER_LOST || error == ER_CLIENT_INTERACTION_TIMEOUT || error == CR_UNKNOWN_ERROR)
28382838
{
28392839
mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql));
28402840
return -2;
@@ -4241,7 +4241,7 @@ static bool mariadb_st_free_result_sets(SV *sth, imp_sth_t *imp_sth, bool free_l
42414241

42424242
/* This is error for previous unfetched result ret. So do not report server errors to caller which is expecting new result set. */
42434243
error = mysql_errno(imp_dbh->pmysql);
4244-
if (error == CR_COMMANDS_OUT_OF_SYNC || error == CR_OUT_OF_MEMORY || error == CR_SERVER_GONE_ERROR || error == CR_SERVER_LOST || error == CR_UNKNOWN_ERROR)
4244+
if (error == CR_COMMANDS_OUT_OF_SYNC || error == CR_OUT_OF_MEMORY || error == CR_SERVER_GONE_ERROR || error == CR_SERVER_LOST || error == ER_CLIENT_INTERACTION_TIMEOUT || error == CR_UNKNOWN_ERROR)
42454245
{
42464246
mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql));
42474247
return FALSE;
@@ -6432,8 +6432,10 @@ bool mariadb_db_reconnect(SV *h, MYSQL_STMT *stmt)
64326432
if (imp_dbh->pmysql &&
64336433
mysql_errno(imp_dbh->pmysql) != CR_SERVER_GONE_ERROR &&
64346434
mysql_errno(imp_dbh->pmysql) != CR_SERVER_LOST &&
6435+
mysql_errno(imp_dbh->pmysql) != ER_CLIENT_INTERACTION_TIMEOUT &&
64356436
(!stmt || (mysql_stmt_errno(stmt) != CR_SERVER_GONE_ERROR &&
64366437
mysql_stmt_errno(stmt) != CR_SERVER_LOST &&
6438+
mysql_stmt_errno(stmt) != ER_CLIENT_INTERACTION_TIMEOUT &&
64376439
mysql_stmt_errno(stmt) != CR_STMT_CLOSED)))
64386440
{
64396441
/* Other error */

dbdimp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
#define CR_STMT_CLOSED 2056
8787
#endif
8888

89+
/* Macro was added in MySQL 8.0.24 */
90+
#ifndef ER_CLIENT_INTERACTION_TIMEOUT
91+
#define ER_CLIENT_INTERACTION_TIMEOUT 4031
92+
#endif
93+
8994

9095
/********************************************************************
9196
* Standard Perl macros which are not defined in every Perl version *

t/15reconnect.t

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $dbh = DbiTestConnect($test_dsn, $test_user, $test_password,
1616
{ RaiseError => 1, PrintError => 0 });
1717
$dbh->disconnect();
1818

19-
plan tests => 21 * 2;
19+
plan tests => 30 * 2;
2020

2121
for my $mariadb_server_prepare (0, 1) {
2222
$dbh= DBI->connect("$test_dsn;mariadb_server_prepare=$mariadb_server_prepare;mariadb_server_prepare_disable_fallback=1", $test_user, $test_password,
@@ -74,5 +74,34 @@ ok($dbh->{Active}, "checking for reactivated handle");
7474

7575
$sth->finish();
7676

77+
ok($dbh->do("SET SESSION wait_timeout=1"), "set wait_timeout to 1");
78+
79+
note("call perl sleep 2 for implicit disconnect due to wait_timeout");
80+
sleep(2);
81+
82+
ok($sth = $dbh->prepare("SELECT 1"), "implicitly reconnecting handle with preparing statement");
83+
84+
ok($sth->execute(), "execute prepared statement");
85+
86+
ok($dbh->{Active}, "checking for reactivated handle");
87+
88+
ok($sth = $dbh->prepare("SELECT 1"), "prepare statement");
89+
90+
note("call perl sleep 2 for implicit disconnect due to wait_timeout");
91+
sleep(2);
92+
93+
ok($sth->execute(), "implicitly reconnecting handle with executing prepared statement");
94+
95+
ok($dbh->{Active}, "checking for reactivated handle");
96+
97+
$sth->finish();
98+
99+
note("call perl sleep 2 for implicit disconnect due to wait_timeout");
100+
sleep(2);
101+
102+
ok($dbh->do("SELECT 1"), "implicitly reconnecting handle with 'do'");
103+
104+
ok($dbh->{Active}, "checking for reactivated handle");
105+
77106
$dbh->disconnect();
78107
}

0 commit comments

Comments
 (0)