Skip to content

Commit

Permalink
Fixing memory leak when using nameserver discovery and NetworkAddress…
Browse files Browse the repository at this point in the history
…Changed events (#68)

Removing usage of NetworkChange.NetworkAddressChanged usage to refresh discovered name-servers.
  • Loading branch information
MichaCo authored Mar 31, 2020
1 parent db2d7cf commit 3a1488c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
2 changes: 1 addition & 1 deletion src/DnsClient/DnsClient.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.3.0</VersionPrefix>
<VersionPrefix>1.3.1</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)'!='' AND '$(BuildNumber)' != ''">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>

<TargetFrameworks>netstandard1.3;netstandard2.0;netstandard2.1;net45;net471</TargetFrameworks>
Expand Down
19 changes: 0 additions & 19 deletions src/DnsClient/LookupClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,6 @@ internal LookupClient(LookupClientOptions options, DnsMessageHandler udpHandler
{
_resolvedNameServers = NameServer.ResolveNameServers(skipIPv6SiteLocal: true, fallbackToGooglePublicDns: false);
servers = servers.Concat(_resolvedNameServers).ToArray();

try
{
NetworkChange.NetworkAddressChanged += CheckResolvedNameserversCallback;
}
catch
{
// Just in case
}

// This will periodically get triggered on Query calls and
// will perform the same check as on NetworkAddressChanged.
Expand All @@ -408,16 +399,6 @@ internal LookupClient(LookupClientOptions options, DnsMessageHandler udpHandler
Cache = new ResponseCache(true, Settings.MinimumCacheTimeout, Settings.MaximumCacheTimeout);
}

private void CheckResolvedNameserversCallback(object sender, EventArgs args)
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Network change detected, trying to resolve name servers...");
}

CheckResolvedNameservers();
}

private void CheckResolvedNameservers()
{
try
Expand Down

0 comments on commit 3a1488c

Please sign in to comment.