Commit fe6ccd16 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Change read timeout reset timing

parent 10ec0012
...@@ -114,8 +114,6 @@ void writecb(struct ev_loop *loop, ev_io *w, int revents) { ...@@ -114,8 +114,6 @@ void writecb(struct ev_loop *loop, ev_io *w, int revents) {
int ClientHandler::noop() { return 0; } int ClientHandler::noop() { return 0; }
int ClientHandler::read_clear() { int ClientHandler::read_clear() {
ev_timer_again(conn_.loop, &conn_.rt);
for (;;) { for (;;) {
if (rb_.rleft() && on_read() != 0) { if (rb_.rleft() && on_read() != 0) {
return -1; return -1;
...@@ -124,6 +122,10 @@ int ClientHandler::read_clear() { ...@@ -124,6 +122,10 @@ int ClientHandler::read_clear() {
rb_.reset(); rb_.reset();
} else if (rb_.wleft() == 0) { } else if (rb_.wleft() == 0) {
conn_.rlimit.stopw(); conn_.rlimit.stopw();
if (reset_conn_rtimer_required_) {
reset_conn_rtimer_required_ = false;
ev_timer_again(conn_.loop, &conn_.rt);
}
return 0; return 0;
} }
...@@ -134,6 +136,10 @@ int ClientHandler::read_clear() { ...@@ -134,6 +136,10 @@ int ClientHandler::read_clear() {
auto nread = conn_.read_clear(rb_.last, rb_.wleft()); auto nread = conn_.read_clear(rb_.last, rb_.wleft());
if (nread == 0) { if (nread == 0) {
if (reset_conn_rtimer_required_) {
reset_conn_rtimer_required_ = false;
ev_timer_again(conn_.loop, &conn_.rt);
}
return 0; return 0;
} }
...@@ -208,8 +214,6 @@ int ClientHandler::tls_handshake() { ...@@ -208,8 +214,6 @@ int ClientHandler::tls_handshake() {
} }
int ClientHandler::read_tls() { int ClientHandler::read_tls() {
ev_timer_again(conn_.loop, &conn_.rt);
ERR_clear_error(); ERR_clear_error();
for (;;) { for (;;) {
...@@ -221,6 +225,11 @@ int ClientHandler::read_tls() { ...@@ -221,6 +225,11 @@ int ClientHandler::read_tls() {
rb_.reset(); rb_.reset();
} else if (rb_.wleft() == 0) { } else if (rb_.wleft() == 0) {
conn_.rlimit.stopw(); conn_.rlimit.stopw();
if (reset_conn_rtimer_required_) {
reset_conn_rtimer_required_ = false;
ev_timer_again(conn_.loop, &conn_.rt);
}
return 0; return 0;
} }
...@@ -231,6 +240,11 @@ int ClientHandler::read_tls() { ...@@ -231,6 +240,11 @@ int ClientHandler::read_tls() {
auto nread = conn_.read_tls(rb_.last, rb_.wleft()); auto nread = conn_.read_tls(rb_.last, rb_.wleft());
if (nread == 0) { if (nread == 0) {
if (reset_conn_rtimer_required_) {
reset_conn_rtimer_required_ = false;
ev_timer_again(conn_.loop, &conn_.rt);
}
return 0; return 0;
} }
...@@ -391,7 +405,8 @@ ClientHandler::ClientHandler(Worker *worker, int fd, SSL *ssl, ...@@ -391,7 +405,8 @@ ClientHandler::ClientHandler(Worker *worker, int fd, SSL *ssl,
faddr_(faddr), faddr_(faddr),
worker_(worker), worker_(worker),
left_connhd_len_(NGHTTP2_CLIENT_MAGIC_LEN), left_connhd_len_(NGHTTP2_CLIENT_MAGIC_LEN),
should_close_after_write_(false) { should_close_after_write_(false),
reset_conn_rtimer_required_(false) {
++worker_->get_worker_stat()->num_connections; ++worker_->get_worker_stat()->num_connections;
...@@ -497,6 +512,10 @@ void ClientHandler::reset_upstream_write_timeout(ev_tstamp t) { ...@@ -497,6 +512,10 @@ void ClientHandler::reset_upstream_write_timeout(ev_tstamp t) {
} }
} }
void ClientHandler::signal_reset_upstream_conn_rtimer() {
reset_conn_rtimer_required_ = true;
}
int ClientHandler::validate_next_proto() { int ClientHandler::validate_next_proto() {
const unsigned char *next_proto = nullptr; const unsigned char *next_proto = nullptr;
unsigned int next_proto_len; unsigned int next_proto_len;
......
...@@ -86,6 +86,7 @@ public: ...@@ -86,6 +86,7 @@ public:
struct ev_loop *get_loop() const; struct ev_loop *get_loop() const;
void reset_upstream_read_timeout(ev_tstamp t); void reset_upstream_read_timeout(ev_tstamp t);
void reset_upstream_write_timeout(ev_tstamp t); void reset_upstream_write_timeout(ev_tstamp t);
void signal_reset_upstream_conn_rtimer();
int validate_next_proto(); int validate_next_proto();
const std::string &get_ipaddr() const; const std::string &get_ipaddr() const;
const std::string &get_port() const; const std::string &get_port() const;
...@@ -161,6 +162,7 @@ private: ...@@ -161,6 +162,7 @@ private:
// The number of bytes of HTTP/2 client connection header to read // The number of bytes of HTTP/2 client connection header to read
size_t left_connhd_len_; size_t left_connhd_len_;
bool should_close_after_write_; bool should_close_after_write_;
bool reset_conn_rtimer_required_;
ReadBuf rb_; ReadBuf rb_;
}; };
......
...@@ -411,6 +411,9 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame, ...@@ -411,6 +411,9 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame,
verbose_on_frame_recv_callback(session, frame, user_data); verbose_on_frame_recv_callback(session, frame, user_data);
} }
auto upstream = static_cast<Http2Upstream *>(user_data); auto upstream = static_cast<Http2Upstream *>(user_data);
auto handler = upstream->get_client_handler();
handler->signal_reset_upstream_conn_rtimer();
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_DATA: { case NGHTTP2_DATA: {
......
...@@ -247,6 +247,11 @@ int htp_hdrs_completecb(http_parser *htp) { ...@@ -247,6 +247,11 @@ int htp_hdrs_completecb(http_parser *htp) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "HTTP request headers completed"; ULOG(INFO, upstream) << "HTTP request headers completed";
} }
auto handler = upstream->get_client_handler();
handler->signal_reset_upstream_conn_rtimer();
auto downstream = upstream->get_downstream(); auto downstream = upstream->get_downstream();
auto &req = downstream->request(); auto &req = downstream->request();
...@@ -323,7 +328,7 @@ int htp_hdrs_completecb(http_parser *htp) { ...@@ -323,7 +328,7 @@ int htp_hdrs_completecb(http_parser *htp) {
req.authority = host->value; req.authority = host->value;
} }
if (upstream->get_client_handler()->get_ssl()) { if (handler->get_ssl()) {
req.scheme = "https"; req.scheme = "https";
} else { } else {
req.scheme = "http"; req.scheme = "http";
...@@ -336,7 +341,6 @@ int htp_hdrs_completecb(http_parser *htp) { ...@@ -336,7 +341,6 @@ int htp_hdrs_completecb(http_parser *htp) {
downstream->set_request_state(Downstream::HEADER_COMPLETE); downstream->set_request_state(Downstream::HEADER_COMPLETE);
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY
auto handler = upstream->get_client_handler();
auto worker = handler->get_worker(); auto worker = handler->get_worker();
auto mruby_ctx = worker->get_mruby_context(); auto mruby_ctx = worker->get_mruby_context();
...@@ -355,7 +359,7 @@ int htp_hdrs_completecb(http_parser *htp) { ...@@ -355,7 +359,7 @@ int htp_hdrs_completecb(http_parser *htp) {
} }
rv = downstream->attach_downstream_connection( rv = downstream->attach_downstream_connection(
upstream->get_client_handler()->get_downstream_connection(downstream)); handler->get_downstream_connection(downstream));
if (rv != 0) { if (rv != 0) {
downstream->set_request_state(Downstream::CONNECT_FAIL); downstream->set_request_state(Downstream::CONNECT_FAIL);
...@@ -377,6 +381,10 @@ namespace { ...@@ -377,6 +381,10 @@ namespace {
int htp_bodycb(http_parser *htp, const char *data, size_t len) { int htp_bodycb(http_parser *htp, const char *data, size_t len) {
int rv; int rv;
auto upstream = static_cast<HttpsUpstream *>(htp->data); auto upstream = static_cast<HttpsUpstream *>(htp->data);
auto handler = upstream->get_client_handler();
handler->signal_reset_upstream_conn_rtimer();
auto downstream = upstream->get_downstream(); auto downstream = upstream->get_downstream();
rv = downstream->push_upload_data_chunk( rv = downstream->push_upload_data_chunk(
reinterpret_cast<const uint8_t *>(data), len); reinterpret_cast<const uint8_t *>(data), len);
......
...@@ -143,6 +143,10 @@ namespace { ...@@ -143,6 +143,10 @@ namespace {
void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type, void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type,
spdylay_frame *frame, void *user_data) { spdylay_frame *frame, void *user_data) {
auto upstream = static_cast<SpdyUpstream *>(user_data); auto upstream = static_cast<SpdyUpstream *>(user_data);
auto handler = upstream->get_client_handler();
handler->signal_reset_upstream_conn_rtimer();
switch (type) { switch (type) {
case SPDYLAY_SYN_STREAM: { case SPDYLAY_SYN_STREAM: {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
...@@ -281,7 +285,6 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type, ...@@ -281,7 +285,6 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type,
downstream->set_request_state(Downstream::HEADER_COMPLETE); downstream->set_request_state(Downstream::HEADER_COMPLETE);
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY
auto handler = upstream->get_client_handler();
auto worker = handler->get_worker(); auto worker = handler->get_worker();
auto mruby_ctx = worker->get_mruby_context(); auto mruby_ctx = worker->get_mruby_context();
...@@ -419,6 +422,10 @@ void on_data_recv_callback(spdylay_session *session, uint8_t flags, ...@@ -419,6 +422,10 @@ void on_data_recv_callback(spdylay_session *session, uint8_t flags,
auto upstream = static_cast<SpdyUpstream *>(user_data); auto upstream = static_cast<SpdyUpstream *>(user_data);
auto downstream = static_cast<Downstream *>( auto downstream = static_cast<Downstream *>(
spdylay_session_get_stream_user_data(session, stream_id)); spdylay_session_get_stream_user_data(session, stream_id));
auto handler = upstream->get_client_handler();
handler->signal_reset_upstream_conn_rtimer();
if (downstream && (flags & SPDYLAY_DATA_FLAG_FIN)) { if (downstream && (flags & SPDYLAY_DATA_FLAG_FIN)) {
if (!downstream->validate_request_recv_body_length()) { if (!downstream->validate_request_recv_body_length()) {
upstream->rst_stream(downstream, SPDYLAY_PROTOCOL_ERROR); upstream->rst_stream(downstream, SPDYLAY_PROTOCOL_ERROR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment