diff --git a/DnsServerCore/Dns/Applications/DnsServerInternal.cs b/DnsServerCore/Dns/Applications/DnsServerInternal.cs index b8492ce1..377f94f1 100644 --- a/DnsServerCore/Dns/Applications/DnsServerInternal.cs +++ b/DnsServerCore/Dns/Applications/DnsServerInternal.cs @@ -46,9 +46,9 @@ namespace DnsServerCore.Dns.Applications #endregion - public Task DirectQueryAsync(DnsQuestionRecord question, int timeout = 2000) + public Task DirectQueryAsync(DnsQuestionRecord question) { - return _dnsServer.DirectQueryAsync(question, timeout); + return _dnsServer.DirectQueryAsync(question); } public void WriteLog(string message) diff --git a/DnsServerCore/Dns/Zones/AuthZone.cs b/DnsServerCore/Dns/Zones/AuthZone.cs index 71628cc1..ad55a9e9 100644 --- a/DnsServerCore/Dns/Zones/AuthZone.cs +++ b/DnsServerCore/Dns/Zones/AuthZone.cs @@ -169,8 +169,8 @@ namespace DnsServerCore.Dns.Zones //resolve addresses try { - DnsDatagram response = await dnsServer.DirectQueryAsync(new DnsQuestionRecord(nsDomain, DnsResourceRecordType.A, DnsClass.IN)); - if ((response != null) && (response.Answer.Count > 0)) + DnsDatagram response = await dnsServer.DirectQueryAsync(new DnsQuestionRecord(nsDomain, DnsResourceRecordType.A, DnsClass.IN)).WithTimeout(2000); + if (response.Answer.Count > 0) { IReadOnlyList addresses = DnsClient.ParseResponseA(response); foreach (IPAddress address in addresses) @@ -184,8 +184,8 @@ namespace DnsServerCore.Dns.Zones { try { - DnsDatagram response = await dnsServer.DirectQueryAsync(new DnsQuestionRecord(nsDomain, DnsResourceRecordType.AAAA, DnsClass.IN)); - if ((response != null) && (response.Answer.Count > 0)) + DnsDatagram response = await dnsServer.DirectQueryAsync(new DnsQuestionRecord(nsDomain, DnsResourceRecordType.AAAA, DnsClass.IN)).WithTimeout(2000); + if (response.Answer.Count > 0) { IReadOnlyList addresses = DnsClient.ParseResponseAAAA(response); foreach (IPAddress address in addresses) diff --git a/DnsServerCore/Dns/Zones/SecondaryZone.cs b/DnsServerCore/Dns/Zones/SecondaryZone.cs index 2ae742a2..c5617cf1 100644 --- a/DnsServerCore/Dns/Zones/SecondaryZone.cs +++ b/DnsServerCore/Dns/Zones/SecondaryZone.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; +using TechnitiumLibrary.IO; using TechnitiumLibrary.Net.Dns; using TechnitiumLibrary.Net.Dns.ResourceRecords; @@ -91,11 +92,11 @@ namespace DnsServerCore.Dns.Zones SecondaryZone secondaryZone = new SecondaryZone(dnsServer, name); DnsQuestionRecord soaQuestion = new DnsQuestionRecord(name, DnsResourceRecordType.SOA, DnsClass.IN); - DnsDatagram soaResponse = null; + DnsDatagram soaResponse; if (primaryNameServerAddresses == null) { - soaResponse = await secondaryZone._dnsServer.DirectQueryAsync(soaQuestion); + soaResponse = await secondaryZone._dnsServer.DirectQueryAsync(soaQuestion).WithTimeout(2000); } else { @@ -107,7 +108,7 @@ namespace DnsServerCore.Dns.Zones soaResponse = await dnsClient.ResolveAsync(soaQuestion); } - if ((soaResponse == null) || (soaResponse.Answer.Count == 0) || (soaResponse.Answer[0].Type != DnsResourceRecordType.SOA)) + if ((soaResponse.Answer.Count == 0) || (soaResponse.Answer[0].Type != DnsResourceRecordType.SOA)) throw new DnsServerException("DNS Server failed to find SOA record for: " + name); DnsSOARecord receivedSoa = soaResponse.Answer[0].RDATA as DnsSOARecord; diff --git a/DnsServerCore/Dns/Zones/StubZone.cs b/DnsServerCore/Dns/Zones/StubZone.cs index a661de24..099a1407 100644 --- a/DnsServerCore/Dns/Zones/StubZone.cs +++ b/DnsServerCore/Dns/Zones/StubZone.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using TechnitiumLibrary.IO; using TechnitiumLibrary.Net.Dns; using TechnitiumLibrary.Net.Dns.ResourceRecords; @@ -76,11 +77,11 @@ namespace DnsServerCore.Dns.Zones StubZone stubZone = new StubZone(dnsServer, name); DnsQuestionRecord soaQuestion = new DnsQuestionRecord(name, DnsResourceRecordType.SOA, DnsClass.IN); - DnsDatagram soaResponse = null; + DnsDatagram soaResponse; if (primaryNameServerAddresses == null) { - soaResponse = await stubZone._dnsServer.DirectQueryAsync(soaQuestion); + soaResponse = await stubZone._dnsServer.DirectQueryAsync(soaQuestion).WithTimeout(2000); } else { @@ -92,7 +93,7 @@ namespace DnsServerCore.Dns.Zones soaResponse = await dnsClient.ResolveAsync(soaQuestion); } - if ((soaResponse == null) || (soaResponse.Answer.Count == 0) || (soaResponse.Answer[0].Type != DnsResourceRecordType.SOA)) + if ((soaResponse.Answer.Count == 0) || (soaResponse.Answer[0].Type != DnsResourceRecordType.SOA)) throw new DnsServerException("DNS Server failed to find SOA record for: " + name); DnsSOARecord receivedSoa = soaResponse.Answer[0].RDATA as DnsSOARecord;