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) {