From 2a4f324f8a1716f7ad0f08a89d82eb244b7f532d Mon Sep 17 00:00:00 2001 From: "romanov.ah" Date: Thu, 22 Aug 2024 15:19:49 +0500 Subject: [PATCH] fix: remove ServiceDiscoveryIPv4 caching --- Vostok.Commons.Environment/EnvironmentInfo.cs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Vostok.Commons.Environment/EnvironmentInfo.cs b/Vostok.Commons.Environment/EnvironmentInfo.cs index d842b8e..7f9e97d 100644 --- a/Vostok.Commons.Environment/EnvironmentInfo.cs +++ b/Vostok.Commons.Environment/EnvironmentInfo.cs @@ -7,7 +7,6 @@ using System.Net.Sockets; using System.Reflection; using System.Runtime.InteropServices; -using System.Threading.Tasks; using JetBrains.Annotations; namespace Vostok.Commons.Environment @@ -25,12 +24,11 @@ internal static class EnvironmentInfo private static Lazy application = new Lazy(ObtainApplicationName); private static Lazy host = new Lazy(ObtainHostname); private static Lazy fqdn = new Lazy(ObtainFQDN); + private static Lazy serviceDiscoveryIPv4 = new Lazy(ObtainServiceDiscoveryIPv4); private static Lazy processName = new Lazy(GetProcessNameOrNull); private static Lazy homeDirectory = new Lazy(ObtainHomeDirectory); private static Lazy processId = new Lazy(GetProcessIdOrNull); - private static readonly TimeSpan CacheTtl = TimeSpan.FromSeconds(3); - /// /// Returns the name of the application. /// @@ -47,9 +45,9 @@ internal static class EnvironmentInfo public static string FQDN => fqdn.Value; /// - /// Returns the IPv4 of the machine running the application. + /// Returns the IPv4 through which the application is accessible on the hosting network. /// - public static volatile string ServiceDiscoveryIPv4; + public static string ServiceDiscoveryIPv4 => serviceDiscoveryIPv4.Value; /// /// Returns the name of current process. @@ -71,18 +69,6 @@ internal static class EnvironmentInfo /// public static string HomeDirectory => homeDirectory.Value; - static EnvironmentInfo() - { - UpdateAndSchedule(); - } - - private static void UpdateAndSchedule() - { - ServiceDiscoveryIPv4 = ObtainServiceDiscoveryIPv4(); - - Task.Delay(CacheTtl).ContinueWith(_ => UpdateAndSchedule()); - } - private static string ObtainApplicationName() { try