From 717e7ae8b2170510b9edb35ab5b2fadf071420e1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 27 Aug 2021 18:29:06 +0900 Subject: [PATCH] nghttpx: Add --frontend-http3-read-timeout option Add --frontend-http3-read-timeout option. QUIC idle timeout option will be added later. --- gennghttpxfun.py | 1 + src/shrpx.cc | 14 ++++++++++++++ src/shrpx_client_handler.cc | 4 ++++ src/shrpx_config.cc | 6 ++++++ src/shrpx_config.h | 4 ++++ 5 files changed, 29 insertions(+) diff --git a/gennghttpxfun.py b/gennghttpxfun.py index b7c31d87..debaa044 100755 --- a/gennghttpxfun.py +++ b/gennghttpxfun.py @@ -180,6 +180,7 @@ OPTIONS = [ "bpf-program-file", "no-bpf", "http2-altsvc", + "frontend-http3-read-timeout", ] LOGVARS = [ diff --git a/src/shrpx.cc b/src/shrpx.cc index be8135be..e19f0aad 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1590,6 +1590,9 @@ void fill_default_config(Config *config) { // Read timeout for HTTP2 upstream connection timeoutconf.http2_read = 3_min; + // Read timeout for HTTP3 upstream connection + timeoutconf.http3_read = 3_min; + // Read timeout for non-HTTP2 upstream connection timeoutconf.read = 1_min; @@ -2073,6 +2076,10 @@ Timeout: Specify read timeout for HTTP/2 frontend connection. Default: )" << util::duration_str(config->conn.upstream.timeout.http2_read) << R"( + --frontend-http3-read-timeout= + Specify read timeout for HTTP/3 frontend connection. + Default: )" + << util::duration_str(config->conn.upstream.timeout.http3_read) << R"( --frontend-read-timeout= Specify read timeout for HTTP/1.1 frontend connection. Default: )" @@ -3589,6 +3596,8 @@ int main(int argc, char **argv) { {SHRPX_OPT_BPF_PROGRAM_FILE.c_str(), required_argument, &flag, 169}, {SHRPX_OPT_NO_BPF.c_str(), no_argument, &flag, 170}, {SHRPX_OPT_HTTP2_ALTSVC.c_str(), required_argument, &flag, 171}, + {SHRPX_OPT_FRONTEND_HTTP3_READ_TIMEOUT.c_str(), required_argument, + &flag, 172}, {nullptr, 0, nullptr, 0}}; int option_index = 0; @@ -4404,6 +4413,11 @@ int main(int argc, char **argv) { // --http2-altsvc cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_ALTSVC, StringRef{optarg}); break; + case 172: + // --frontend-http3-read-timeout + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP3_READ_TIMEOUT, + StringRef{optarg}); + break; default: break; } diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index d58c9a5f..c9327397 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -519,6 +519,10 @@ void ClientHandler::setup_http3_upstream( upstream_ = std::move(upstream); alpn_ = StringRef::from_lit("h3"); write_ = &ClientHandler::write_quic; + + auto config = get_config(); + + reset_upstream_read_timeout(config->conn.upstream.timeout.http3_read); } #endif // ENABLE_HTTP3 diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 3c0a63dc..59643183 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -2393,6 +2393,9 @@ int option_lookup_token(const char *name, size_t namelen) { if (util::strieq_l("frontend-http2-read-timeou", name, 26)) { return SHRPX_OPTID_FRONTEND_HTTP2_READ_TIMEOUT; } + if (util::strieq_l("frontend-http3-read-timeou", name, 26)) { + return SHRPX_OPTID_FRONTEND_HTTP3_READ_TIMEOUT; + } if (util::strieq_l("frontend-keep-alive-timeou", name, 26)) { return SHRPX_OPTID_FRONTEND_KEEP_ALIVE_TIMEOUT; } @@ -3873,6 +3876,9 @@ int parse_config(Config *config, int optid, const StringRef &opt, return 0; } + case SHRPX_OPTID_FRONTEND_HTTP3_READ_TIMEOUT: + return parse_duration(&config->conn.upstream.timeout.http3_read, opt, + optarg); case SHRPX_OPTID_CONF: LOG(WARN) << "conf: ignored"; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 4b1bd8fd..facc3acf 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -367,6 +367,8 @@ constexpr auto SHRPX_OPT_BPF_PROGRAM_FILE = StringRef::from_lit("bpf-program-file"); constexpr auto SHRPX_OPT_NO_BPF = StringRef::from_lit("no-bpf"); constexpr auto SHRPX_OPT_HTTP2_ALTSVC = StringRef::from_lit("http2-altsvc"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP3_READ_TIMEOUT = + StringRef::from_lit("frontend-http3-read-timeout"); constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8; @@ -955,6 +957,7 @@ struct ConnectionConfig { struct { struct { ev_tstamp http2_read; + ev_tstamp http3_read; ev_tstamp read; ev_tstamp write; ev_tstamp idle_read; @@ -1160,6 +1163,7 @@ enum { SHRPX_OPTID_FRONTEND_HTTP2_SETTINGS_TIMEOUT, SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_BITS, SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_SIZE, + SHRPX_OPTID_FRONTEND_HTTP3_READ_TIMEOUT, SHRPX_OPTID_FRONTEND_KEEP_ALIVE_TIMEOUT, SHRPX_OPTID_FRONTEND_MAX_REQUESTS, SHRPX_OPTID_FRONTEND_NO_TLS,