@@ -965,7 +965,7 @@ static int check_connection(THD *thd)
965
965
return (ER_HANDSHAKE_ERROR);
966
966
}
967
967
DBUG_PRINT (" info" , (" IO layer change in progress..." ));
968
- if (sslaccept (ssl_acceptor_fd, net->vio , thd-> variables . net_wait_timeout ))
968
+ if (sslaccept (ssl_acceptor_fd, net->vio , net-> read_timeout ))
969
969
{
970
970
DBUG_PRINT (" error" , (" Failed to accept new SSL connection" ));
971
971
inc_host_errors (&thd->remote .sin_addr );
@@ -994,7 +994,6 @@ static int check_connection(THD *thd)
994
994
if ((thd->client_capabilities & CLIENT_TRANSACTIONS) &&
995
995
opt_using_transactions)
996
996
net->return_status = &thd->server_status ;
997
- net->read_timeout =(uint ) thd->variables .net_read_timeout ;
998
997
999
998
char *user= end;
1000
999
char *passwd= strend (user)+1 ;
@@ -1138,6 +1137,10 @@ pthread_handler_t handle_one_connection(void *arg)
1138
1137
Security_context *sctx= thd->security_ctx ;
1139
1138
net->no_send_error = 0 ;
1140
1139
1140
+ /* Use "connect_timeout" value during connection phase */
1141
+ net_set_read_timeout (net, connect_timeout);
1142
+ net_set_write_timeout (net, connect_timeout);
1143
+
1141
1144
if ((error=check_connection (thd)))
1142
1145
{ // Wrong permissions
1143
1146
if (error > 0 )
@@ -1180,6 +1183,10 @@ pthread_handler_t handle_one_connection(void *arg)
1180
1183
thd->init_for_queries ();
1181
1184
}
1182
1185
1186
+ /* Connect completed, set read/write timeouts back to tdefault */
1187
+ net_set_read_timeout (net, thd->variables .net_read_timeout );
1188
+ net_set_write_timeout (net, thd->variables .net_write_timeout );
1189
+
1183
1190
while (!net->error && net->vio != 0 &&
1184
1191
!(thd->killed == THD::KILL_CONNECTION))
1185
1192
{
@@ -1486,7 +1493,7 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion)
1486
1493
#ifndef EMBEDDED_LIBRARY
1487
1494
1488
1495
/*
1489
- Read one command from socket and execute it (query or simple command).
1496
+ Read one command from connection and execute it (query or simple command).
1490
1497
This function is called in loop from thread function.
1491
1498
SYNOPSIS
1492
1499
do_command()
@@ -1497,24 +1504,26 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion)
1497
1504
1498
1505
bool do_command (THD *thd)
1499
1506
{
1500
- char *packet;
1501
- uint old_timeout;
1507
+ char *packet= 0 ;
1502
1508
ulong packet_length;
1503
- NET *net;
1509
+ NET *net= &thd-> net ;
1504
1510
enum enum_server_command command;
1505
1511
DBUG_ENTER (" do_command" );
1506
1512
1507
- net= &thd->net ;
1508
1513
/*
1509
1514
indicator of uninitialized lex => normal flow of errors handling
1510
1515
(see my_message_sql)
1511
1516
*/
1512
1517
thd->lex ->current_select = 0 ;
1513
1518
1514
- packet=0 ;
1515
- old_timeout=net->read_timeout ;
1516
- /* Wait max for 8 hours */
1517
- net->read_timeout =(uint ) thd->variables .net_wait_timeout ;
1519
+ /*
1520
+ This thread will do a blocking read from the client which
1521
+ will be interrupted when the next command is received from
1522
+ the client, the connection is closed or "net_wait_timeout"
1523
+ number of seconds has passed
1524
+ */
1525
+ net_set_read_timeout (net, thd->variables .net_wait_timeout );
1526
+
1518
1527
thd->clear_error (); // Clear error message
1519
1528
1520
1529
net_new_transaction (net);
@@ -1543,7 +1552,10 @@ bool do_command(THD *thd)
1543
1552
vio_description (net->vio ), command,
1544
1553
command_name[command]));
1545
1554
}
1546
- net->read_timeout =old_timeout; // restore it
1555
+
1556
+ /* Restore read timeout value */
1557
+ net_set_read_timeout (net, thd->variables .net_read_timeout );
1558
+
1547
1559
/*
1548
1560
packet_length contains length of data, as it was stored in packet
1549
1561
header. In case of malformed header, packet_length can be zero.
0 commit comments