diff --git a/src/Common/isLocalAddress.cpp b/src/Common/isLocalAddress.cpp index 772e0363904..1e6cfb1c592 100644 --- a/src/Common/isLocalAddress.cpp +++ b/src/Common/isLocalAddress.cpp @@ -79,33 +79,6 @@ struct NetworkInterfaces : public boost::noncopyable { freeifaddrs(ifaddr); } - - static std::shared_ptr instance() - { - static constexpr int NET_INTERFACE_VALID_PERIOD_MS = 30000; - static std::shared_ptr nf = std::make_shared(); - static std::atomic last_updated_time = std::chrono::steady_clock::now(); - static std::shared_mutex nf_mtx; - - auto now = std::chrono::steady_clock::now(); - - if (std::chrono::duration_cast(now - last_updated_time.load()).count() > NET_INTERFACE_VALID_PERIOD_MS) - { - std::unique_lock lock(nf_mtx); - /// It's possible that last_updated_time after we get lock - if (std::chrono::duration_cast(now - last_updated_time.load()).count() > NET_INTERFACE_VALID_PERIOD_MS) - { - nf = std::make_shared(); - last_updated_time.store(now); - } - return nf; - } - else - { - std::shared_lock lock(nf_mtx); - return nf; - } - } }; } @@ -143,7 +116,8 @@ bool isLocalAddress(const Poco::Net::IPAddress & address) } } - return NetworkInterfaces::instance()->hasAddress(address); + static NetworkInterfaces network_interfaces; + return network_interfaces.hasAddress(address); }