From 238dfa7f786fc62f758b8432bd6932c41066d72c Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Sat, 18 Apr 2020 02:55:12 -0300 Subject: [PATCH] Drop idle connections regularly The check here on "only if we have some idle workers" fails catastrophically with one worker because that worker is always occupied when this code gets called because of how the loop works and so connections don't get expired at all. --- lokimq/connections.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lokimq/connections.cpp b/lokimq/connections.cpp index 9ab1f5f..5674efa 100644 --- a/lokimq/connections.cpp +++ b/lokimq/connections.cpp @@ -248,11 +248,14 @@ void LokiMQ::proxy_expire_idle_peers() { if (info.outgoing()) { auto idle = std::chrono::steady_clock::now() - info.last_activity; if (idle > info.idle_expiry) { - LMQ_LOG(debug, "Closing outgoing connection to ", it->first, ": idle timeout reached"); + LMQ_LOG(debug, "Closing outgoing connection to ", it->first, ": idle time (", + std::chrono::duration_cast(idle).count(), "ms) reached connection timeout (", + info.idle_expiry.count(), "ms)"); ++it; // The below is going to delete our current element proxy_close_connection(info.conn_index, CLOSE_LINGER); } else { - LMQ_LOG(trace, "Not closing ", it->first, ": ", idle.count(), "ms <= ", info.idle_expiry.count(), "ms"); + LMQ_LOG(trace, "Not closing ", it->first, ": ", std::chrono::duration_cast(idle).count(), + "ms <= ", info.idle_expiry.count(), "ms"); ++it; continue; } @@ -265,13 +268,9 @@ void LokiMQ::proxy_expire_idle_peers() { void LokiMQ::proxy_conn_cleanup() { LMQ_TRACE("starting proxy connections cleanup"); - // Drop idle connections (if we haven't done it in a while) but *only* if we have some idle - // general workers: if we don't have any idle workers then we may still have incoming messages which - // we haven't processed yet and those messages might end up resetting the last activity time. - if (static_cast(workers.size()) < general_workers) { - LMQ_TRACE("closing idle connections"); - proxy_expire_idle_peers(); - } + // Drop idle connections (if we haven't done it in a while) + LMQ_TRACE("closing idle connections"); + proxy_expire_idle_peers(); auto now = std::chrono::steady_clock::now();