Skip to content

Commit

Permalink
MDEV-8096 vio timeouts are multiplied by 1000 for ssl
Browse files Browse the repository at this point in the history
in when using vio->read_timeout (and write_timeout) to set
timeouts of a new vio, as in:

  vio_timeout(vio, 0, old_vio.read_timeout)
  vio_timeout(vio, 0, old_vio.write_timeout)

remember that timeouts are stored in ms, but vio_timeout()'s
argument is in seconds.
  • Loading branch information
vuvova committed May 5, 2015
1 parent d3a3adb commit 95797b9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
24 changes: 24 additions & 0 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5912,6 +5912,8 @@ void do_connect(struct st_command *command)
my_bool con_ssl= 0, con_compress= 0;
my_bool con_pipe= 0;
my_bool con_shm __attribute__ ((unused))= 0;
int read_timeout= 0;
int write_timeout= 0;
struct st_connection* con_slot;

static DYNAMIC_STRING ds_connection_name;
Expand Down Expand Up @@ -6008,6 +6010,16 @@ void do_connect(struct st_command *command)
con_pipe= 1;
else if (length == 3 && !strncmp(con_options, "SHM", 3))
con_shm= 1;
else if (strncasecmp(con_options, "read_timeout=",
sizeof("read_timeout=")-1) == 0)
{
read_timeout= atoi(con_options + sizeof("read_timeout=")-1);
}
else if (strncasecmp(con_options, "write_timeout=",
sizeof("write_timeout=")-1) == 0)
{
write_timeout= atoi(con_options + sizeof("write_timeout=")-1);
}
else
die("Illegal option to connect: %.*s",
(int) (end - con_options), con_options);
Expand Down Expand Up @@ -6080,6 +6092,18 @@ void do_connect(struct st_command *command)
if (opt_protocol)
mysql_options(con_slot->mysql, MYSQL_OPT_PROTOCOL, (char*) &opt_protocol);

if (read_timeout)
{
mysql_options(con_slot->mysql, MYSQL_OPT_READ_TIMEOUT,
(char*)&read_timeout);
}

if (write_timeout)
{
mysql_options(con_slot->mysql, MYSQL_OPT_WRITE_TIMEOUT,
(char*)&write_timeout);
}

#ifdef HAVE_SMEM
if (con_shm)
{
Expand Down
7 changes: 7 additions & 0 deletions mysql-test/r/ssl_timeout.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# connect with read timeout so SLEEP() should timeout
# Check ssl turned on
SHOW STATUS LIKE 'Ssl_cipher';
Variable_name Value
Ssl_cipher DHE-RSA-AES256-SHA
SELECT SLEEP(600);
ERROR HY000: Lost connection to MySQL server during query
21 changes: 21 additions & 0 deletions mysql-test/t/ssl_timeout.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--source include/have_ssl_communication.inc

# Save the initial number of concurrent sessions
--source include/count_sessions.inc

--echo # connect with read timeout so SLEEP() should timeout
connect (ssl_con,localhost,root,,,,,SSL read_timeout=5);

--echo # Check ssl turned on
--replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
SHOW STATUS LIKE 'Ssl_cipher';

# --error CR_SERVER_LOST
--error 2013
SELECT SLEEP(600);

connection default;
disconnect ssl_con;

# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
7 changes: 5 additions & 2 deletions vio/vio.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ my_bool vio_reset(Vio* vio, enum enum_vio_type type,
Propagate the timeout values. Necessary to also propagate
the underlying proprieties associated with the timeout,
such as the socket blocking mode.
note: old_vio.read_timeout/old_vio.write_timeout is stored in ms
but vio_timeout() takes seconds as argument, hence the / 1000
*/
if (old_vio.read_timeout >= 0)
ret|= vio_timeout(vio, 0, old_vio.read_timeout);
ret|= vio_timeout(vio, 0, old_vio.read_timeout / 1000);

if (old_vio.write_timeout >= 0)
ret|= vio_timeout(vio, 1, old_vio.write_timeout);
ret|= vio_timeout(vio, 1, old_vio.write_timeout / 1000);

DBUG_RETURN(MY_TEST(ret));
}
Expand Down

0 comments on commit 95797b9

Please sign in to comment.