nghttpx: Don't re-enter offline if it is already in offline mode

This commit is contained in:
Tatsuhiro Tsujikawa 2016-05-21 10:28:16 +09:00
parent dce7288658
commit e26d6a2b27
3 changed files with 20 additions and 1 deletions

View File

@ -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<double>::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

View File

@ -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

View File

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