Skip to content

Commit 85f473f

Browse files
author
Andrzej Religa
committed
WL#14978 Decrease connection timeout to the endpoint servers
Changes default endpoint connect timeout to 5 seconds. RB: 27488
1 parent e7db1a9 commit 85f473f

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

router/src/metadata_cache/include/mysqlrouter/metadata_cache.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "mysqlrouter/datatypes.h"
4747
#include "mysqlrouter/metadata.h"
4848
#include "mysqlrouter/metadata_cache_datatypes.h"
49+
#include "mysqlrouter/mysql_session.h"
4950
#include "tcp_address.h"
5051

5152
namespace metadata_cache {
@@ -60,8 +61,10 @@ constexpr const std::chrono::milliseconds kDefaultAuthCacheRefreshInterval{
6061
2000};
6162
// blank cluster name means pick the 1st (and only) cluster
6263
constexpr const std::string_view kDefaultMetadataCluster{""};
63-
constexpr const unsigned int kDefaultConnectTimeout{30};
64-
constexpr const unsigned int kDefaultReadTimeout{30};
64+
constexpr const unsigned int kDefaultConnectTimeout{
65+
mysqlrouter::MySQLSession::kDefaultConnectTimeout};
66+
constexpr const unsigned int kDefaultReadTimeout{
67+
mysqlrouter::MySQLSession::kDefaultReadTimeout};
6568

6669
constexpr const std::string_view kNodeTagHidden{"_hidden"};
6770
constexpr const std::string_view kNodeTagDisconnectWhenHidden{

router/src/router/include/mysqlrouter/mysql_session.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ class Option<Opt, std::nullptr_t> {
153153

154154
class ROUTER_LIB_EXPORT MySQLSession {
155155
public:
156-
static const int kDefaultConnectTimeout = 15;
157-
static const int kDefaultReadTimeout = 30;
156+
static constexpr int kDefaultConnectTimeout = 5;
157+
static constexpr int kDefaultReadTimeout = 30;
158158
typedef std::vector<const char *> Row;
159159
typedef std::function<bool(const Row &)> RowProcessor;
160160
typedef std::function<void(unsigned, MYSQL_FIELD *)> FieldValidator;

router/src/router/tests/test_config_generator.cc

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ class TestConfigGenerator : public mysqlrouter::ConfigGenerator {
160160
}
161161
};
162162

163-
const std::string kDefaultConnectTimeout =
164-
std::to_string(mysqlrouter::MySQLSession::kDefaultConnectTimeout);
165-
const std::string kDefaultReadTimeout =
166-
std::to_string(mysqlrouter::MySQLSession::kDefaultReadTimeout);
167-
168163
class ReplayerWithMockSSL : public MySQLSessionReplayer {
169164
public:
170165
void set_ssl_options(mysql_ssl_mode ssl_mode, const std::string &tls_version,
@@ -1602,8 +1597,8 @@ TEST_F(CreateConfigGeneratorTest, create_config_basic) {
16021597
"[DEFAULT]",
16031598
"name=myrouter",
16041599
"user=mysqlrouter",
1605-
"connect_timeout=" + kDefaultConnectTimeout,
1606-
"read_timeout=" + kDefaultReadTimeout,
1600+
"connect_timeout=5",
1601+
"read_timeout=30",
16071602
"dynamic_state=state_file_name.json",
16081603
"client_ssl_cert=" + tmp_path.join("router-cert.pem").str(),
16091604
"client_ssl_key=" + tmp_path.join("router-key.pem").str(),
@@ -1690,8 +1685,8 @@ TEST_F(CreateConfigGeneratorTest, create_config_system_instance) {
16901685
std::vector<std::string> expected_config_lines = {
16911686
"# File automatically generated during MySQL Router bootstrap",
16921687
"[DEFAULT]",
1693-
"connect_timeout=" + kDefaultConnectTimeout,
1694-
"read_timeout=" + kDefaultReadTimeout,
1688+
"connect_timeout=5",
1689+
"read_timeout=30",
16951690
"dynamic_state=state_file_name.json",
16961691
"client_ssl_cert=" + tmp_path.join("router-cert.pem").str(),
16971692
"client_ssl_key=" + tmp_path.join("router-key.pem").str(),
@@ -1781,8 +1776,8 @@ TEST_F(CreateConfigGeneratorTest, create_config_base_port) {
17811776
std::vector<std::string> expected_config_lines = {
17821777
"# File automatically generated during MySQL Router bootstrap",
17831778
"[DEFAULT]",
1784-
"connect_timeout=" + kDefaultConnectTimeout,
1785-
"read_timeout=" + kDefaultReadTimeout,
1779+
"connect_timeout=5",
1780+
"read_timeout=30",
17861781
"dynamic_state=state_file_name.json",
17871782
"client_ssl_cert=" + tmp_path.join("router-cert.pem").str(),
17881783
"client_ssl_key=" + tmp_path.join("router-key.pem").str(),
@@ -1876,8 +1871,8 @@ TEST_F(CreateConfigGeneratorTest, create_config_skip_tcp) {
18761871
std::vector<std::string> expected_config_lines = {
18771872
"# File automatically generated during MySQL Router bootstrap",
18781873
"[DEFAULT]",
1879-
"connect_timeout=" + kDefaultConnectTimeout,
1880-
"read_timeout=" + kDefaultReadTimeout,
1874+
"connect_timeout=5",
1875+
"read_timeout=30",
18811876
"dynamic_state=state_file_name.json",
18821877
"client_ssl_cert=" + tmp_path.join("router-cert.pem").str(),
18831878
"client_ssl_key=" + tmp_path.join("router-key.pem").str(),
@@ -1964,8 +1959,8 @@ TEST_F(CreateConfigGeneratorTest, create_config_use_sockets) {
19641959
std::vector<std::string> expected_config_lines = {
19651960
"# File automatically generated during MySQL Router bootstrap",
19661961
"[DEFAULT]",
1967-
"connect_timeout=" + kDefaultConnectTimeout,
1968-
"read_timeout=" + kDefaultReadTimeout,
1962+
"connect_timeout=5",
1963+
"read_timeout=30",
19691964
"dynamic_state=state_file_name.json",
19701965
"client_ssl_cert=" + tmp_path.join("router-cert.pem").str(),
19711966
"client_ssl_key=" + tmp_path.join("router-key.pem").str(),
@@ -2062,8 +2057,8 @@ TEST_F(CreateConfigGeneratorTest, create_config_bind_address) {
20622057
"[DEFAULT]",
20632058
"name=myrouter",
20642059
"user=mysqlrouter",
2065-
"connect_timeout=" + kDefaultConnectTimeout,
2066-
"read_timeout=" + kDefaultReadTimeout,
2060+
"connect_timeout=5",
2061+
"read_timeout=30",
20672062
"dynamic_state=state_file_name.json",
20682063
"client_ssl_cert=" + tmp_path.join("router-cert.pem").str(),
20692064
"client_ssl_key=" + tmp_path.join("router-key.pem").str(),
@@ -2155,8 +2150,8 @@ TEST_F(CreateConfigGeneratorTest, create_config_disable_rest) {
21552150
"[DEFAULT]",
21562151
"name=myrouter",
21572152
"user=mysqlrouter",
2158-
"connect_timeout=" + kDefaultConnectTimeout,
2159-
"read_timeout=" + kDefaultReadTimeout,
2153+
"connect_timeout=5",
2154+
"read_timeout=30",
21602155
"dynamic_state=state_file_name.json",
21612156
"client_ssl_cert=" + tmp_path.join("router-cert.pem").str(),
21622157
"client_ssl_key=" + tmp_path.join("router-key.pem").str(),

router/src/routing/include/mysqlrouter/routing.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef MYSQLROUTER_ROUTING_INCLUDED
2626
#define MYSQLROUTER_ROUTING_INCLUDED
2727

28+
#include "mysqlrouter/mysql_session.h"
2829
#include "mysqlrouter/routing_export.h"
2930

3031
#include <chrono>
@@ -53,7 +54,8 @@ constexpr const int kDefaultMaxConnections{0};
5354
* Constant defining how long we wait to establish connection with the server
5455
* before we give up.
5556
*/
56-
constexpr const std::chrono::seconds kDefaultDestinationConnectionTimeout{1};
57+
constexpr const std::chrono::seconds kDefaultDestinationConnectionTimeout{
58+
mysqlrouter::MySQLSession::kDefaultConnectTimeout};
5759

5860
/** Maximum connect or handshake errors per host.
5961
*

router/src/routing/tests/test_routing.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ TEST_F(RoutingTests, Defaults) {
7575
ASSERT_EQ(routing::kDefaultWaitTimeout, 0);
7676
ASSERT_EQ(routing::kDefaultMaxConnections, 0);
7777
ASSERT_EQ(routing::kDefaultDestinationConnectionTimeout,
78-
std::chrono::seconds(1));
78+
std::chrono::seconds(5));
7979
ASSERT_EQ(routing::kDefaultBindAddress, "127.0.0.1");
8080
ASSERT_EQ(routing::kDefaultNetBufferLength, 16384U);
8181
ASSERT_EQ(routing::kDefaultMaxConnectErrors, 100ULL);

0 commit comments

Comments
 (0)