From 06ed17ff263ffe3366bc62bbc5473a39f91cdb57 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 14 Jul 2012 21:47:28 +0900 Subject: [PATCH] shrpx: fixed timeout change is not triggered when tunneling. For upstream timeout, it seems OpenSSL backed bufferevent does not remove timeout. Set large timeout as a workaround. --- examples/shrpx_downstream.cc | 33 +++++++++++++++---------- examples/shrpx_downstream_connection.cc | 5 ++-- examples/shrpx_downstream_connection.h | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/examples/shrpx_downstream.cc b/examples/shrpx_downstream.cc index 486ffe6..0df0d4b 100644 --- a/examples/shrpx_downstream.cc +++ b/examples/shrpx_downstream.cc @@ -522,7 +522,25 @@ int htp_hdrs_completecb(http_parser *htp) downstream->set_response_connection_close(!http_should_keep_alive(htp)); downstream->set_response_state(Downstream::HEADER_COMPLETE); downstream->get_upstream()->on_downstream_header_complete(downstream); - return 0; + + if(downstream->tunnel_established()) { + downstream->get_downstream_connection()->set_tunneling_timeout(); + // For tunneling, we remove upstream read timeouts. But it seems + // libevent cannot remove timeouts for SSL based bufferevent. Set + // long timeout here as a workaround. + timeval rtv = { 3600*24, 0 }; + timeval wtv = { 30, 0 }; + downstream->get_upstream()->get_client_handler() + ->set_upstream_timeouts(&rtv, &wtv); + } + + if(downstream->get_request_method() == "HEAD") { + // Ignore the response body. HEAD response may contain + // Content-Length or Transfer-Encoding: chunked. + return 1; + } else { + return 0; + } } } // namespace @@ -572,21 +590,10 @@ int htp_msg_completecb(http_parser *htp) Downstream *downstream; downstream = reinterpret_cast(htp->data); - if(downstream->tunnel_established()) { - // For tunneling, we remove timeouts. - downstream->get_downstream_connection()->remove_timeouts(); - } - downstream->set_response_state(Downstream::MSG_COMPLETE); downstream->get_upstream()->on_downstream_body_complete(downstream); - if(downstream->get_request_method() == "HEAD") { - // Ignore the response body. HEAD response may contain - // Content-Length or Transfer-Encoding: chunked. - return 1; - } else { - return 0; - } + return 0; } } // namespace diff --git a/examples/shrpx_downstream_connection.cc b/examples/shrpx_downstream_connection.cc index 7e22e68..bf77ef5 100644 --- a/examples/shrpx_downstream_connection.cc +++ b/examples/shrpx_downstream_connection.cc @@ -110,10 +110,11 @@ void DownstreamConnection::start_waiting_response() } } -void DownstreamConnection::remove_timeouts() +void DownstreamConnection::set_tunneling_timeout() { if(bev_) { - bufferevent_set_timeouts(bev_, 0, 0); + bufferevent_set_timeouts(bev_, 0, + &get_config()->downstream_write_timeout); } } diff --git a/examples/shrpx_downstream_connection.h b/examples/shrpx_downstream_connection.h index beb4b9d..edef771 100644 --- a/examples/shrpx_downstream_connection.h +++ b/examples/shrpx_downstream_connection.h @@ -47,7 +47,7 @@ public: ClientHandler* get_client_handler(); Downstream* get_downstream(); void start_waiting_response(); - void remove_timeouts(); + void set_tunneling_timeout(); private: ClientHandler *client_handler_; bufferevent *bev_;