This is an automated email from the ASF dual-hosted git repository. wwbmmm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push: new 0ef35f34 Fix hc ref (#2367) 0ef35f34 is described below commit 0ef35f3498dbfbdef3d8dcda62e815c1b1e06d37 Author: Bright Chen <chenguangmin...@foxmail.com> AuthorDate: Tue Sep 19 20:14:45 2023 +0800 Fix hc ref (#2367) * Fix hc ref * Add HCEnabled function --- src/brpc/builtin/connections_service.cpp | 2 +- src/brpc/socket.cpp | 2 +- src/brpc/socket.h | 6 +++++- src/brpc/socket_map.cpp | 6 ++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/brpc/builtin/connections_service.cpp b/src/brpc/builtin/connections_service.cpp index fdef0e68..02adc56b 100644 --- a/src/brpc/builtin/connections_service.cpp +++ b/src/brpc/builtin/connections_service.cpp @@ -161,7 +161,7 @@ void ConnectionsService::PrintConnections( if (ret < 0) { continue; } else if (ret > 0) { - if (ptr->_health_check_interval_s <= 0) { + if (!ptr->HCEnabled()) { // Sockets without HC will soon be destroyed continue; } diff --git a/src/brpc/socket.cpp b/src/brpc/socket.cpp index da1c8e5a..3cef97df 100644 --- a/src/brpc/socket.cpp +++ b/src/brpc/socket.cpp @@ -959,7 +959,7 @@ int Socket::SetFailed(int error_code, const char* error_fmt, ...) { // Do health-checking even if we're not connected before, needed // by Channel to revive never-connected socket when server side // comes online. - if (_health_check_interval_s > 0) { + if (HCEnabled()) { bool expect = false; if (_hc_started.compare_exchange_strong(expect, true, diff --git a/src/brpc/socket.h b/src/brpc/socket.h index 0e43122c..f4c3cf90 100644 --- a/src/brpc/socket.h +++ b/src/brpc/socket.h @@ -320,10 +320,14 @@ public: // ip/port of the other end of the connection. butil::EndPoint remote_side() const { return _remote_side; } - // Positive value enables health checking. // Initialized by SocketOptions.health_check_interval_s. int health_check_interval() const { return _health_check_interval_s; } + // True if health checking is enabled. + bool HCEnabled() const { + return _health_check_interval_s > 0 && _is_hc_related_ref_held; + } + // When someone holds a health-checking-related reference, // this function need to be called to make health checking run normally. void SetHCRelatedRefHeld() { _is_hc_related_ref_held = true; } diff --git a/src/brpc/socket_map.cpp b/src/brpc/socket_map.cpp index d169afd8..a451c1a6 100644 --- a/src/brpc/socket_map.cpp +++ b/src/brpc/socket_map.cpp @@ -149,7 +149,7 @@ SocketMap::~SocketMap() { for (Map::iterator it = _map.begin(); it != _map.end(); ++it) { SingleConnection* sc = &it->second; if ((!sc->socket->Failed() || - sc->socket->health_check_interval() > 0/*HC enabled*/) && + sc->socket->HCEnabled()) && sc->ref_count != 0) { ++nleft; if (nleft == 0) { @@ -216,9 +216,7 @@ int SocketMap::Insert(const SocketMapKey& key, SocketId* id, std::unique_lock<butil::Mutex> mu(_mutex); SingleConnection* sc = _map.seek(key); if (sc) { - if (!sc->socket->Failed() || - (sc->socket->health_check_interval() > 0 && - sc->socket->IsHCRelatedRefHeld())/*HC enabled*/) { + if (!sc->socket->Failed() || sc->socket->HCEnabled()) { ++sc->ref_count; *id = sc->socket->id(); return 0; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org