From 53a41c953da60147f6c39ba634bb74ff00d004ae Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 21 Jan 2015 21:43:49 +0900 Subject: [PATCH] nghttpx: Don't call ev_TYPE_set macro while watcher is active --- src/shrpx_client_handler.cc | 4 ++-- src/shrpx_connect_blocker.cc | 4 ++++ src/shrpx_http2_session.cc | 6 ++++++ src/shrpx_http_downstream_connection.cc | 9 +++++---- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 9e8ea18f..e9414f6e 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -583,14 +583,14 @@ struct ev_loop *ClientHandler::get_loop() const { } void ClientHandler::reset_upstream_read_timeout(ev_tstamp t) { - ev_timer_set(&rt_, 0., t); + rt_.repeat = t; if (ev_is_active(&rt_)) { ev_timer_again(loop_, &rt_); } } void ClientHandler::reset_upstream_write_timeout(ev_tstamp t) { - ev_timer_set(&wt_, 0., t); + wt_.repeat = t; if (ev_is_active(&wt_)) { ev_timer_again(loop_, &wt_); } diff --git a/src/shrpx_connect_blocker.cc b/src/shrpx_connect_blocker.cc index 34df7c67..3eb6de16 100644 --- a/src/shrpx_connect_blocker.cc +++ b/src/shrpx_connect_blocker.cc @@ -50,6 +50,10 @@ bool ConnectBlocker::blocked() const { return ev_is_active(&timer_); } void ConnectBlocker::on_success() { sleep_ = INITIAL_SLEEP; } void ConnectBlocker::on_failure() { + if (ev_is_active(&timer_)) { + return; + } + sleep_ = std::min(128., sleep_ * 2); LOG(WARN) << "connect failure, start sleeping " << sleep_; diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index a373c219..f35b31fe 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -385,6 +385,12 @@ int Http2Session::initiate_connection() { } } + // rev_ and wev_ could possibly be active here. Since calling + // ev_io_set is not allowed while watcher is active, we have to + // stop them just in case. + ev_io_stop(loop_, &rev_); + ev_io_stop(loop_, &wev_); + ev_io_set(&rev_, fd_, EV_READ); ev_io_set(&wev_, fd_, EV_WRITE); diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 92d098a6..6dd8f86a 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -212,8 +212,8 @@ int HttpDownstreamConnection::attach_downstream(Downstream *downstream) { ev_set_cb(&rev_, readcb); - ev_timer_set(&rt_, 0., get_config()->downstream_read_timeout); - + rt_.repeat = get_config()->downstream_read_timeout; + ev_timer_again(loop_, &rt_); // TODO we should have timeout for connection establishment ev_timer_again(loop_, &wt_); @@ -424,10 +424,11 @@ void HttpDownstreamConnection::detach_downstream(Downstream *downstream) { ev_io_start(loop_, &rev_); ev_io_stop(loop_, &wev_); + ev_set_cb(&rev_, idle_readcb); + ev_timer_stop(loop_, &wt_); - ev_set_cb(&rev_, idle_readcb); - ev_timer_set(&rt_, 0., get_config()->downstream_idle_read_timeout); + rt_.repeat = get_config()->downstream_idle_read_timeout; ev_set_cb(&rt_, idle_timeoutcb); ev_timer_again(loop_, &rt_); }