nghttpx: Add --backend-connect-timeout option
This commit is contained in:
parent
7549341081
commit
00a8c378d4
|
@ -148,6 +148,7 @@ OPTIONS = [
|
||||||
"backend-http2-decoder-dynamic-table-size",
|
"backend-http2-decoder-dynamic-table-size",
|
||||||
"ecdh-curves",
|
"ecdh-curves",
|
||||||
"tls-sct-dir",
|
"tls-sct-dir",
|
||||||
|
"backend-connect-timeout",
|
||||||
]
|
]
|
||||||
|
|
||||||
LOGVARS = [
|
LOGVARS = [
|
||||||
|
|
13
src/shrpx.cc
13
src/shrpx.cc
|
@ -1442,6 +1442,7 @@ void fill_default_config(Config *config) {
|
||||||
timeoutconf.write = 30_s;
|
timeoutconf.write = 30_s;
|
||||||
// Timeout for pooled (idle) connections
|
// Timeout for pooled (idle) connections
|
||||||
timeoutconf.idle_read = 2_s;
|
timeoutconf.idle_read = 2_s;
|
||||||
|
timeoutconf.connect = 30_s;
|
||||||
timeoutconf.max_backoff = 120_s;
|
timeoutconf.max_backoff = 120_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1787,6 +1788,11 @@ Timeout:
|
||||||
Specify write timeout for backend connection.
|
Specify write timeout for backend connection.
|
||||||
Default: )"
|
Default: )"
|
||||||
<< util::duration_str(config->conn.downstream->timeout.write) << R"(
|
<< util::duration_str(config->conn.downstream->timeout.write) << R"(
|
||||||
|
--backend-connect-timeout=<DURATION>
|
||||||
|
Specify timeout before establishing TCP connection to
|
||||||
|
backend.
|
||||||
|
Default: )"
|
||||||
|
<< util::duration_str(config->conn.downstream->timeout.connect) << R"(
|
||||||
--backend-keep-alive-timeout=<DURATION>
|
--backend-keep-alive-timeout=<DURATION>
|
||||||
Specify keep-alive timeout for backend connection.
|
Specify keep-alive timeout for backend connection.
|
||||||
Default: )"
|
Default: )"
|
||||||
|
@ -2956,6 +2962,8 @@ int main(int argc, char **argv) {
|
||||||
required_argument, &flag, 139},
|
required_argument, &flag, 139},
|
||||||
{SHRPX_OPT_ECDH_CURVES.c_str(), required_argument, &flag, 140},
|
{SHRPX_OPT_ECDH_CURVES.c_str(), required_argument, &flag, 140},
|
||||||
{SHRPX_OPT_TLS_SCT_DIR.c_str(), required_argument, &flag, 141},
|
{SHRPX_OPT_TLS_SCT_DIR.c_str(), required_argument, &flag, 141},
|
||||||
|
{SHRPX_OPT_BACKEND_CONNECT_TIMEOUT.c_str(), required_argument, &flag,
|
||||||
|
142},
|
||||||
{nullptr, 0, nullptr, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
@ -3624,6 +3632,11 @@ int main(int argc, char **argv) {
|
||||||
// --tls-sct-dir
|
// --tls-sct-dir
|
||||||
cmdcfgs.emplace_back(SHRPX_OPT_TLS_SCT_DIR, StringRef{optarg});
|
cmdcfgs.emplace_back(SHRPX_OPT_TLS_SCT_DIR, StringRef{optarg});
|
||||||
break;
|
break;
|
||||||
|
case 142:
|
||||||
|
// --backend-connect-timeout
|
||||||
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_CONNECT_TIMEOUT,
|
||||||
|
StringRef{optarg});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1657,6 +1657,11 @@ int option_lookup_token(const char *name, size_t namelen) {
|
||||||
return SHRPX_OPTID_BACKEND_RESPONSE_BUFFER;
|
return SHRPX_OPTID_BACKEND_RESPONSE_BUFFER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
if (util::strieq_l("backend-connect-timeou", name, 22)) {
|
||||||
|
return SHRPX_OPTID_BACKEND_CONNECT_TIMEOUT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
|
@ -2162,6 +2167,9 @@ int parse_config(Config *config, int optid, const StringRef &opt,
|
||||||
return parse_duration(&config->conn.downstream->timeout.read, opt, optarg);
|
return parse_duration(&config->conn.downstream->timeout.read, opt, optarg);
|
||||||
case SHRPX_OPTID_BACKEND_WRITE_TIMEOUT:
|
case SHRPX_OPTID_BACKEND_WRITE_TIMEOUT:
|
||||||
return parse_duration(&config->conn.downstream->timeout.write, opt, optarg);
|
return parse_duration(&config->conn.downstream->timeout.write, opt, optarg);
|
||||||
|
case SHRPX_OPTID_BACKEND_CONNECT_TIMEOUT:
|
||||||
|
return parse_duration(&config->conn.downstream->timeout.connect, opt,
|
||||||
|
optarg);
|
||||||
case SHRPX_OPTID_STREAM_READ_TIMEOUT:
|
case SHRPX_OPTID_STREAM_READ_TIMEOUT:
|
||||||
return parse_duration(&config->http2.timeout.stream_read, opt, optarg);
|
return parse_duration(&config->http2.timeout.stream_read, opt, optarg);
|
||||||
case SHRPX_OPTID_STREAM_WRITE_TIMEOUT:
|
case SHRPX_OPTID_STREAM_WRITE_TIMEOUT:
|
||||||
|
|
|
@ -310,6 +310,8 @@ constexpr auto SHRPX_OPT_BACKEND_HTTP2_DECODER_DYNAMIC_TABLE_SIZE =
|
||||||
StringRef::from_lit("backend-http2-decoder-dynamic-table-size");
|
StringRef::from_lit("backend-http2-decoder-dynamic-table-size");
|
||||||
constexpr auto SHRPX_OPT_ECDH_CURVES = StringRef::from_lit("ecdh-curves");
|
constexpr auto SHRPX_OPT_ECDH_CURVES = StringRef::from_lit("ecdh-curves");
|
||||||
constexpr auto SHRPX_OPT_TLS_SCT_DIR = StringRef::from_lit("tls-sct-dir");
|
constexpr auto SHRPX_OPT_TLS_SCT_DIR = StringRef::from_lit("tls-sct-dir");
|
||||||
|
constexpr auto SHRPX_OPT_BACKEND_CONNECT_TIMEOUT =
|
||||||
|
StringRef::from_lit("backend-connect-timeout");
|
||||||
|
|
||||||
constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8;
|
constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8;
|
||||||
|
|
||||||
|
@ -718,6 +720,7 @@ struct DownstreamConfig {
|
||||||
ev_tstamp read;
|
ev_tstamp read;
|
||||||
ev_tstamp write;
|
ev_tstamp write;
|
||||||
ev_tstamp idle_read;
|
ev_tstamp idle_read;
|
||||||
|
ev_tstamp connect;
|
||||||
// The maximum backoff while checking health check for offline
|
// The maximum backoff while checking health check for offline
|
||||||
// backend or while detaching failed backend from load balancing
|
// backend or while detaching failed backend from load balancing
|
||||||
// group temporarily.
|
// group temporarily.
|
||||||
|
@ -850,6 +853,7 @@ enum {
|
||||||
SHRPX_OPTID_API_MAX_REQUEST_BODY,
|
SHRPX_OPTID_API_MAX_REQUEST_BODY,
|
||||||
SHRPX_OPTID_BACKEND,
|
SHRPX_OPTID_BACKEND,
|
||||||
SHRPX_OPTID_BACKEND_ADDRESS_FAMILY,
|
SHRPX_OPTID_BACKEND_ADDRESS_FAMILY,
|
||||||
|
SHRPX_OPTID_BACKEND_CONNECT_TIMEOUT,
|
||||||
SHRPX_OPTID_BACKEND_CONNECTIONS_PER_FRONTEND,
|
SHRPX_OPTID_BACKEND_CONNECTIONS_PER_FRONTEND,
|
||||||
SHRPX_OPTID_BACKEND_CONNECTIONS_PER_HOST,
|
SHRPX_OPTID_BACKEND_CONNECTIONS_PER_HOST,
|
||||||
SHRPX_OPTID_BACKEND_HTTP_PROXY_URI,
|
SHRPX_OPTID_BACKEND_HTTP_PROXY_URI,
|
||||||
|
|
|
@ -313,6 +313,8 @@ int Http2Session::initiate_connection() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto &downstreamconf = *get_config()->conn.downstream;
|
||||||
|
|
||||||
const auto &proxy = get_config()->downstream_http_proxy;
|
const auto &proxy = get_config()->downstream_http_proxy;
|
||||||
if (!proxy.host.empty() && state_ == DISCONNECTED) {
|
if (!proxy.host.empty() && state_ == DISCONNECTED) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
|
@ -351,7 +353,7 @@ int Http2Session::initiate_connection() {
|
||||||
|
|
||||||
conn_.wlimit.startw();
|
conn_.wlimit.startw();
|
||||||
|
|
||||||
// TODO we should have timeout for connection establishment
|
conn_.wt.repeat = downstreamconf.timeout.connect;
|
||||||
ev_timer_again(conn_.loop, &conn_.wt);
|
ev_timer_again(conn_.loop, &conn_.wt);
|
||||||
|
|
||||||
write_ = &Http2Session::connected;
|
write_ = &Http2Session::connected;
|
||||||
|
@ -484,7 +486,8 @@ int Http2Session::initiate_connection() {
|
||||||
if (state_ != CONNECTED) {
|
if (state_ != CONNECTED) {
|
||||||
state_ = CONNECTING;
|
state_ = CONNECTING;
|
||||||
conn_.wlimit.startw();
|
conn_.wlimit.startw();
|
||||||
// TODO we should have timeout for connection establishment
|
|
||||||
|
conn_.wt.repeat = downstreamconf.timeout.connect;
|
||||||
ev_timer_again(conn_.loop, &conn_.wt);
|
ev_timer_again(conn_.loop, &conn_.wt);
|
||||||
} else {
|
} else {
|
||||||
conn_.rlimit.startw();
|
conn_.rlimit.startw();
|
||||||
|
@ -1857,6 +1860,12 @@ int Http2Session::connected() {
|
||||||
SSLOG(INFO, this) << "Connection established";
|
SSLOG(INFO, this) << "Connection established";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto &downstreamconf = *get_config()->conn.downstream;
|
||||||
|
|
||||||
|
// Reset timeout for write. Previously, we set timeout for connect.
|
||||||
|
conn_.wt.repeat = downstreamconf.timeout.write;
|
||||||
|
ev_timer_again(conn_.loop, &conn_.wt);
|
||||||
|
|
||||||
conn_.rlimit.startw();
|
conn_.rlimit.startw();
|
||||||
|
|
||||||
read_ = &Http2Session::read_clear;
|
read_ = &Http2Session::read_clear;
|
||||||
|
|
|
@ -315,7 +315,7 @@ int HttpDownstreamConnection::attach_downstream(Downstream *downstream) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO we should have timeout for connection establishment
|
conn_.wt.repeat = downstreamconf.timeout.connect;
|
||||||
ev_timer_again(conn_.loop, &conn_.wt);
|
ev_timer_again(conn_.loop, &conn_.wt);
|
||||||
} else {
|
} else {
|
||||||
// we may set read timer cb to idle_timeoutcb. Reset again.
|
// we may set read timer cb to idle_timeoutcb. Reset again.
|
||||||
|
@ -1178,6 +1178,12 @@ int HttpDownstreamConnection::connected() {
|
||||||
DCLOG(INFO, this) << "Connected to downstream host";
|
DCLOG(INFO, this) << "Connected to downstream host";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto &downstreamconf = *get_config()->conn.downstream;
|
||||||
|
|
||||||
|
// Reset timeout for write. Previously, we set timeout for connect.
|
||||||
|
conn_.wt.repeat = downstreamconf.timeout.write;
|
||||||
|
ev_timer_again(conn_.loop, &conn_.wt);
|
||||||
|
|
||||||
conn_.rlimit.startw();
|
conn_.rlimit.startw();
|
||||||
|
|
||||||
ev_set_cb(&conn_.wev, writecb);
|
ev_set_cb(&conn_.wev, writecb);
|
||||||
|
|
|
@ -252,7 +252,9 @@ int LiveCheck::initiate_connection() {
|
||||||
|
|
||||||
conn_.wlimit.startw();
|
conn_.wlimit.startw();
|
||||||
|
|
||||||
// TODO we should have timeout for connection establishment
|
auto &downstreamconf = *get_config()->conn.downstream;
|
||||||
|
|
||||||
|
conn_.wt.repeat = downstreamconf.timeout.connect;
|
||||||
ev_timer_again(conn_.loop, &conn_.wt);
|
ev_timer_again(conn_.loop, &conn_.wt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -274,6 +276,12 @@ int LiveCheck::connected() {
|
||||||
LOG(INFO) << "Connection established";
|
LOG(INFO) << "Connection established";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto &downstreamconf = *get_config()->conn.downstream;
|
||||||
|
|
||||||
|
// Reset timeout for write. Previously, we set timeout for connect.
|
||||||
|
conn_.wt.repeat = downstreamconf.timeout.write;
|
||||||
|
ev_timer_again(conn_.loop, &conn_.wt);
|
||||||
|
|
||||||
conn_.rlimit.startw();
|
conn_.rlimit.startw();
|
||||||
|
|
||||||
if (conn_.tls.ssl) {
|
if (conn_.tls.ssl) {
|
||||||
|
|
Loading…
Reference in New Issue