From 53b9d52125a979b986f7674614ab4eac386e4ddc Mon Sep 17 00:00:00 2001 From: SmithThe4th Date: Thu, 6 Apr 2023 15:31:45 -0400 Subject: [PATCH] [PM-1675] Timeout or transient error when verifying domains (#2835) * Increased timeout of the dns resolve method and changed the lifetime of the dnsResolverService to scoped * Reverted to using singleton as this was recommneded on the docs and also registered lookup client as a singleton * Registerered a singleton service of ILookupClient * replaced unused serviceProvider with a discard --- .../VerifyOrganizationDomainCommand.cs | 3 ++- src/Core/Services/Implementations/DnsResolverService.cs | 9 +++++++-- src/SharedWeb/Utilities/ServiceCollectionExtensions.cs | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Core/OrganizationFeatures/OrganizationDomains/VerifyOrganizationDomainCommand.cs b/src/Core/OrganizationFeatures/OrganizationDomains/VerifyOrganizationDomainCommand.cs index a2b38a3573..cfa4ab1481 100644 --- a/src/Core/OrganizationFeatures/OrganizationDomains/VerifyOrganizationDomainCommand.cs +++ b/src/Core/OrganizationFeatures/OrganizationDomains/VerifyOrganizationDomainCommand.cs @@ -60,7 +60,8 @@ public class VerifyOrganizationDomainCommand : IVerifyOrganizationDomainCommand } catch (Exception e) { - _logger.LogError("Error verifying Organization domain. {errorMessage}", e.Message); + _logger.LogError("Error verifying Organization domain: {domain}. {errorMessage}", + domain.DomainName, e.Message); } domain.SetLastCheckedDate(); diff --git a/src/Core/Services/Implementations/DnsResolverService.cs b/src/Core/Services/Implementations/DnsResolverService.cs index c47bd2e588..f55fa43d46 100644 --- a/src/Core/Services/Implementations/DnsResolverService.cs +++ b/src/Core/Services/Implementations/DnsResolverService.cs @@ -5,10 +5,15 @@ namespace Bit.Core.Services; public class DnsResolverService : IDnsResolverService { + private readonly ILookupClient _client; + + public DnsResolverService(ILookupClient client) + { + _client = client; + } public async Task ResolveAsync(string domain, string txtRecord, CancellationToken cancellationToken = default) { - var lookup = new LookupClient(); - var result = await lookup.QueryAsync(new DnsQuestion(domain, QueryType.TXT), cancellationToken); + var result = await _client.QueryAsync(new DnsQuestion(domain, QueryType.TXT), cancellationToken); if (!result.HasError) { return result.Answers.TxtRecords() diff --git a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs index 0af5e60681..dc38579607 100644 --- a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs +++ b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs @@ -19,6 +19,7 @@ using Bit.Core.Utilities; using Bit.Core.Vault.Services; using Bit.Infrastructure.Dapper; using Bit.Infrastructure.EntityFramework; +using DnsClient; using IdentityModel; using IdentityServer4.AccessTokenValidation; using IdentityServer4.Configuration; @@ -176,6 +177,11 @@ public static class ServiceCollectionExtensions services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(_ => + { + var options = new LookupClientOptions { Timeout = TimeSpan.FromSeconds(15) }; + return new LookupClient(options); + }); services.AddSingleton(); services.AddSingleton(); services.AddTokenizers();