Skip to content

Commit

Permalink
Delay HC to avoid HC-timing issues in UT
Browse files Browse the repository at this point in the history
  • Loading branch information
gejun committed Sep 9, 2018
1 parent 79d0f86 commit c8160cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/brpc/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,9 @@ void Controller::IssueRPC(int64_t start_realtime_us) {
// of the backup call.
const int rc = Socket::Address(_single_server_id, &tmp_sock);
if (rc != 0 || tmp_sock->IsLogOff()) {
SetFailed(EHOSTDOWN, "Not connected to %s yet, server_id=%" PRIu64,
endpoint2str(_remote_side).c_str(), _single_server_id);
tmp_sock.reset(); // Release ref ASAP
SetFailed(EHOSTDOWN, "Not connected to %s yet",
endpoint2str(_remote_side).c_str());
return HandleSendFailed();
}
_current_call.peer_id = _single_server_id;
Expand Down
8 changes: 5 additions & 3 deletions src/brpc/selective_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ class SubChannel : public SocketUser {

int CheckHealth(Socket* ptr) {
if (ptr->health_check_count() == 0) {
LOG(INFO) << "Checking " << *chan;
LOG(INFO) << "Checking " << *chan << " chan=0x" << (void*)chan
<< " Fake" << *ptr;
}
return chan->CheckHealth();
}

void AfterRevived(Socket*) {
LOG(INFO) << "Revived " << *chan;
void AfterRevived(Socket* ptr) {
LOG(INFO) << "Revived " << *chan << " chan=0x" << (void*)chan
<< " Fake" << *ptr;
}
};

Expand Down
6 changes: 5 additions & 1 deletion src/brpc/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,12 @@ int Socket::SetFailed(int error_code, const char* error_fmt, ...) {
// FIXME(gejun): the initial delay should be related to uncommited
// CircuitBreaker and shorter for occasional errors and longer for
// frequent errors.
// NOTE: the delay should be positive right now to avoid HC timing
// issues in UT.
if (_health_check_interval_s > 0) {
PeriodicTaskManager::StartTaskAt(
new HealthCheckTask(id()),
butil::milliseconds_from_now(0)/*FIXME*/);
butil::milliseconds_from_now(100/*NOTE*/));
}
// Wake up all threads waiting on EPOLLOUT when closing fd
_epollout_butex->fetch_add(1, butil::memory_order_relaxed);
Expand Down Expand Up @@ -2613,6 +2615,7 @@ std::string Socket::description() const {
if (local_port > 0) {
butil::string_appendf(&result, "@%d", local_port);
}
butil::string_appendf(&result, " (0x%p)", this);
return result;
}

Expand Down Expand Up @@ -2641,6 +2644,7 @@ ostream& operator<<(ostream& os, const brpc::Socket& sock) {
if (local_port > 0) {
os << '@' << local_port;
}
os << " (0x" << (void*)&sock << ')';
return os;
}
}

0 comments on commit c8160cf

Please sign in to comment.