From e26d6a2b27f345678308e0d26b849e97b0ddd627 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 21 May 2016 10:28:16 +0900 Subject: [PATCH] nghttpx: Don't re-enter offline if it is already in offline mode --- src/shrpx_connect_blocker.cc | 12 +++++++++++- src/shrpx_connect_blocker.h | 5 +++++ src/shrpx_worker.cc | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/shrpx_connect_blocker.cc b/src/shrpx_connect_blocker.cc index ae6a6c60..d70fe5ca 100644 --- a/src/shrpx_connect_blocker.cc +++ b/src/shrpx_connect_blocker.cc @@ -35,7 +35,7 @@ void connect_blocker_cb(struct ev_loop *loop, ev_timer *w, int revents) { } // namespace ConnectBlocker::ConnectBlocker(std::mt19937 &gen, struct ev_loop *loop) - : gen_(gen), loop_(loop), fail_count_(0) { + : gen_(gen), loop_(loop), fail_count_(0), offline_(false) { ev_timer_init(&timer_, connect_blocker_cb, 0., 0.); } @@ -81,6 +81,12 @@ void ConnectBlocker::on_failure() { size_t ConnectBlocker::get_fail_count() const { return fail_count_; } void ConnectBlocker::offline() { + if (offline_) { + return; + } + + offline_ = true; + ev_timer_stop(loop_, &timer_); ev_timer_set(&timer_, std::numeric_limits::max(), 0.); ev_timer_start(loop_, &timer_); @@ -90,6 +96,10 @@ void ConnectBlocker::online() { ev_timer_stop(loop_, &timer_); fail_count_ = 0; + + offline_ = false; } +bool ConnectBlocker::in_offline() const { return offline_; } + } // namespace shrpx diff --git a/src/shrpx_connect_blocker.h b/src/shrpx_connect_blocker.h index 9d60697f..441ac277 100644 --- a/src/shrpx_connect_blocker.h +++ b/src/shrpx_connect_blocker.h @@ -57,6 +57,9 @@ public: // Peer is now considered online void online(); + // Returns true if peer is considered offline. + bool in_offline() const; + private: std::mt19937 gen_; ev_timer timer_; @@ -64,6 +67,8 @@ private: // The number of consecutive connection failure. Reset to 0 on // success. size_t fail_count_; + // true if peer is considered offline. + bool offline_; }; } // namespace diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index 1a620788..d88f48ea 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -478,6 +478,10 @@ size_t match_downstream_addr_group( void downstream_failure(DownstreamAddr *addr) { const auto &connect_blocker = addr->connect_blocker; + if (connect_blocker->in_offline()) { + return; + } + connect_blocker->on_failure(); if (addr->fall == 0) {