Skip to content

Commit f83f4d6

Browse files
committed
Bug#11747227: --CONNECT_TIMEOUT AND --WAIT KEYS ARE NOT TAKE EFFECT
Mysql client does not handle documented --wait command line parameter. Change-Id: I7af489a96d082c628399071ead30a0a7cec4f509
1 parent 1ce3928 commit f83f4d6

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

client/mysql.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,8 @@ static struct my_option my_long_options[] = {
19861986
nullptr},
19871987
{"version", 'V', "Output version information and exit.", nullptr, nullptr,
19881988
nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
1989-
{"wait", 'w', "Wait and retry if connection is down.", nullptr, nullptr,
1990-
nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
1989+
{"wait", 'w', "Wait and retry if connection is down.", &wait_flag,
1990+
&wait_flag, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
19911991
{"connect_timeout", OPT_CONNECT_TIMEOUT,
19921992
"Number of seconds before connection timeout.", &opt_connect_timeout,
19931993
&opt_connect_timeout, nullptr, GET_ULONG, REQUIRED_ARG, 0, 0, 3600 * 12,
@@ -5209,8 +5209,16 @@ static int sql_connect(char *host, char *database, char *user, uint silent) {
52095209
}
52105210
return error;
52115211
}
5212+
// exit after single try if no --wait flag
52125213
if (!wait_flag) return ignore_errors ? -1 : 1;
5213-
if (!message && !silent) {
5214+
// exit after two tries if --wait, but no --force flag provided
5215+
if (!ignore_errors && count > 0) {
5216+
tee_fputs("\n", stderr);
5217+
(void)fflush(stderr);
5218+
return 1;
5219+
}
5220+
5221+
if (!message && (!silent || verbose)) {
52145222
message = true;
52155223
tee_fputs("Waiting", stderr);
52165224
(void)fflush(stderr);
@@ -5219,8 +5227,8 @@ static int sql_connect(char *host, char *database, char *user, uint silent) {
52195227
if (!silent) {
52205228
putc('.', stderr);
52215229
(void)fflush(stderr);
5222-
count++;
52235230
}
5231+
count++;
52245232
}
52255233
}
52265234

mysql-test/r/mysql_wait.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Bug#11747227: --CONNECT_TIMEOUT AND --WAIT KEYS ARE NOT TAKE EFFECT
3+
#
4+
Test --wait with unavailable server host
5+
include/assert_grep.inc [Found Waiting line in mysql client log]
6+
Test --wait with unresolvable server host name
7+
include/assert_grep.inc [No Waiting line in mysql client log]
8+
9+
End of tests

mysql-test/t/mysql_wait.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--echo #
2+
--echo # Bug#11747227: --CONNECT_TIMEOUT AND --WAIT KEYS ARE NOT TAKE EFFECT
3+
--echo #
4+
5+
# test --wait flag
6+
let $MYSQLD_DATADIR= `SELECT @@datadir`;
7+
let $MYSQL_LOG= $MYSQLD_DATADIR/mysql_wait_output.log;
8+
9+
# Wait should attempt a single retry on connectivity issues to a resolvable, but unavailable host
10+
# (simulated with unused IPv4 numeric address and port combination)
11+
# Use -v to output "Waiting" line (to assert retry actually happened)
12+
--echo Test --wait with unavailable server host
13+
--error 1
14+
--exec $MYSQL -v --wait --host=0.0.0.0 --port=1 -e "SELECT 1;" 2>$MYSQL_LOG
15+
16+
--let $assert_text= Found Waiting line in mysql client log
17+
--let $assert_select= Waiting
18+
--let $assert_file= $MYSQL_LOG
19+
--let $assert_count= 1
20+
--source include/assert_grep.inc
21+
22+
# Wait should immediately fail on connectivity issues to unresolvable host name (no retries)
23+
--echo Test --wait with unresolvable server host name
24+
--error 1
25+
--exec $MYSQL -v --wait --host=invalid -e "SELECT 1;" 2>$MYSQL_LOG
26+
27+
--let $assert_text= No Waiting line in mysql client log
28+
--let $assert_select= Waiting
29+
--let $assert_file= $MYSQL_LOG
30+
--let $assert_count= 0
31+
--source include/assert_grep.inc
32+
33+
remove_file $MYSQL_LOG;
34+
35+
--echo
36+
--echo End of tests

0 commit comments

Comments
 (0)