From 16039244ba25dc22c47f9caf6e27492acaff7bb4 Mon Sep 17 00:00:00 2001 From: Swayam-code Date: Tue, 20 Oct 2026 22:09:48 +0530 Subject: [PATCH] MDEV-13718 mysqltest crashes upon --sync_slave_with_master without active connection Report the existing no-active-connection error before querying master status. Stop sync_slave_with_master before it selects a slave after a handled error. Cover disconnected commands, connection preservation and successful replication before and after the error. --- client/mysqltest.cc | 12 +++++- .../r/rpl_mysqltest_closed_connection.result | 41 +++++++++++++++++++ .../t/rpl_mysqltest_closed_connection.test | 41 +++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/rpl/r/rpl_mysqltest_closed_connection.result create mode 100644 mysql-test/suite/rpl/t/rpl_mysqltest_closed_connection.test diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 0f0ecb37c4166..9229eeecc7885 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5436,6 +5436,12 @@ int do_save_master_pos() const char *query; DBUG_ENTER("do_save_master_pos"); + if (!mysql) + { + handle_no_active_connection(curr_command, cur_con, &ds_res); + DBUG_RETURN(1); + } + if (mysql_query(mysql, query= "show master status")) die("failed in 'show master status': %d %s", mysql_errno(mysql), mysql_error(mysql)); @@ -13570,7 +13576,11 @@ int main(int argc, char **argv) case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break; case Q_SYNC_SLAVE_WITH_MASTER: { - do_save_master_pos(); + if (do_save_master_pos()) + { + command->last_argument= command->end; + break; + } if (*command->first_argument) select_connection(command); else diff --git a/mysql-test/suite/rpl/r/rpl_mysqltest_closed_connection.result b/mysql-test/suite/rpl/r/rpl_mysqltest_closed_connection.result new file mode 100644 index 0000000000000..f572430a6e7bc --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_mysqltest_closed_connection.result @@ -0,0 +1,41 @@ +include/master-slave.inc +[connection master] +# Connected master-position commands still replicate successfully. +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1); +connection slave; +SELECT * FROM t1; +a +1 +connection master; +connect con1,localhost,root,,; +disconnect con1; +# MDEV-13718: report a closed connection without switching to a slave. +ERROR 000000: MariaDB server has gone away +2006 +connection="-closed_connection-" +ERROR 000000: MariaDB server has gone away +2006 +connection="-closed_connection-" +ERROR 000000: MariaDB server has gone away +2006 +connection="-closed_connection-" +# The errors are consumed, and both sync forms still work. +connection master; +INSERT INTO t1 VALUES (2); +connection slave; +SELECT * FROM t1 ORDER BY a; +a +1 +2 +connection master; +INSERT INTO t1 VALUES (3); +connection slave1; +SELECT * FROM t1 ORDER BY a; +a +1 +2 +3 +connection master; +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_mysqltest_closed_connection.test b/mysql-test/suite/rpl/t/rpl_mysqltest_closed_connection.test new file mode 100644 index 0000000000000..e1f5494c463b8 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_mysqltest_closed_connection.test @@ -0,0 +1,41 @@ +--source include/master-slave.inc + +--echo # Connected master-position commands still replicate successfully. +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1); +--save_master_pos +--connection slave +--sync_with_master +SELECT * FROM t1; + +--connection master +--connect (con1,localhost,root,,) +--disconnect con1 + +--echo # MDEV-13718: report a closed connection without switching to a slave. +--error 2006 +--save_master_pos +--echo $mysql_errno +--echo connection="$CURRENT_CONNECTION" +--error 2006 +--sync_slave_with_master +--echo $mysql_errno +--echo connection="$CURRENT_CONNECTION" +--error 2006 +--sync_slave_with_master slave1 +--echo $mysql_errno +--echo connection="$CURRENT_CONNECTION" + +--echo # The errors are consumed, and both sync forms still work. +--connection master +INSERT INTO t1 VALUES (2); +--sync_slave_with_master +SELECT * FROM t1 ORDER BY a; +--connection master +INSERT INTO t1 VALUES (3); +--sync_slave_with_master slave1 +SELECT * FROM t1 ORDER BY a; + +--connection master +DROP TABLE t1; +--source include/rpl_end.inc