diff --git a/sqlitecluster/SQLiteNode.cpp b/sqlitecluster/SQLiteNode.cpp index 2a0c7e31b..ff6172389 100644 --- a/sqlitecluster/SQLiteNode.cpp +++ b/sqlitecluster/SQLiteNode.cpp @@ -2625,10 +2625,16 @@ void SQLiteNode::postPoll(fd_map& fdm, uint64_t& nextActivity) { break; case SQLitePeer::PeerPostPollStatus::OK: { - auto lastActivityTime = max(peer->lastSendTime(), peer->lastRecvTime()); - if (lastActivityTime && STimeNow() - lastActivityTime > SQLiteNode::RECV_TIMEOUT - 5 * STIME_US_PER_S) { - SINFO("Close to timeout (" << (STimeNow() - lastActivityTime) << "us since last activity), sending PING to peer '" << peer->name << "'"); - _sendPING(peer); + auto lastRecvTime = peer->lastRecvTime(); + auto now = STimeNow(); + auto elapsed = (now - lastRecvTime); + if (lastRecvTime && elapsed > SQLiteNode::RECV_TIMEOUT - 5 * STIME_US_PER_S) { + // Ping the peer (unless it's been less that 1 second since the last ping). + if (now > (peer->lastPingTime + 1'000'000)) { + SINFO("Close to timeout (" << elapsed << "us since last activity), sending PING to peer '" << peer->name << "'"); + peer->lastPingTime = now; + _sendPING(peer); + } } try { size_t messagesDeqeued = 0; diff --git a/sqlitecluster/SQLitePeer.cpp b/sqlitecluster/SQLitePeer.cpp index 94f4eb5bd..4b8a12bc1 100644 --- a/sqlitecluster/SQLitePeer.cpp +++ b/sqlitecluster/SQLitePeer.cpp @@ -22,6 +22,7 @@ SQLitePeer::SQLitePeer(const string& name_, const string& host_, const STable& p subscribed(false), transactionResponse(Response::NONE), version(), + lastPingTime(0), hash() { } @@ -46,6 +47,7 @@ void SQLitePeer::reset() { subscribed = false; transactionResponse = Response::NONE; version = ""; + lastPingTime = 0, setCommit(0, ""); } diff --git a/sqlitecluster/SQLitePeer.h b/sqlitecluster/SQLitePeer.h index bc07d2155..cb3e07ff3 100644 --- a/sqlitecluster/SQLitePeer.h +++ b/sqlitecluster/SQLitePeer.h @@ -86,6 +86,7 @@ class SQLitePeer { atomic subscribed; atomic transactionResponse; atomic version; + atomic lastPingTime; private: // For initializing the permafollower value from the params list.