From 2244d0d2e2757cb92421fd270ee93328bf782838 Mon Sep 17 00:00:00 2001 From: Lanzheng Liu Date: Fri, 31 May 2024 01:45:59 +0800 Subject: [PATCH] fix dns resolver discard_cache (#497) Signed-off-by: liulanzheng --- net/utils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/utils.cpp b/net/utils.cpp index ed514ed9..010678f3 100644 --- a/net/utils.cpp +++ b/net/utils.cpp @@ -304,8 +304,10 @@ class DefaultResolver : public Resolver { void discard_cache(const char *host, IPAddr ip) override { auto ipaddr = dnscache_.borrow(host); - if (ip.undefined() || ipaddr->empty()) ipaddr.recycle(true); - else { + if (ip.undefined() || ipaddr->empty()) { + ipaddr->delete_all(); + ipaddr.recycle(true); + } else { for (auto itr = ipaddr->rbegin(); itr != ipaddr->rend(); itr++) { if ((*itr)->addr == ip) { ipaddr->erase(*itr);