From afe68ba4f8b3d2d5be54bb44ce7f327064c85697 Mon Sep 17 00:00:00 2001
From: shinestare <995230548@qq.com>
Date: Tue, 29 Oct 2024 09:10:09 +0800
Subject: [PATCH] [collector]bugfix: close connection when common cache is
 timeout (#2786)

Co-authored-by: shown <yuluo08290126@gmail.com>
Co-authored-by: aias00 <rokkki@163.com>
---
 .../collector/collect/common/cache/ConnectionCommonCache.java  | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/collector/collector-common/src/main/java/org/apache/hertzbeat/collector/collect/common/cache/ConnectionCommonCache.java b/collector/collector-common/src/main/java/org/apache/hertzbeat/collector/collect/common/cache/ConnectionCommonCache.java
index d36941d9fee..8e2f603bf03 100644
--- a/collector/collector-common/src/main/java/org/apache/hertzbeat/collector/collect/common/cache/ConnectionCommonCache.java
+++ b/collector/collector-common/src/main/java/org/apache/hertzbeat/collector/collect/common/cache/ConnectionCommonCache.java
@@ -147,8 +147,7 @@ public Optional<C> getCache(T key, boolean refreshCache) {
         }
         if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) {
             log.warn("[connection common cache] is timeout, remove it, key {}.", key);
-            timeoutMap.remove(key);
-            cacheMap.remove(key);
+            removeCache(key);
             return Optional.empty();
         }
         C value = cacheMap.compute(key, (k, v) -> {