取消启动等待DnscryptProxy,因为影响到windows服务启动
This commit is contained in:
parent
eaf9d2bbad
commit
ec06b11d7e
@ -13,7 +13,6 @@ namespace FastGithub.DnscryptProxy
|
||||
{
|
||||
private readonly DnscryptProxyService dnscryptProxyService;
|
||||
private readonly ILogger<DnscryptProxyHostedService> logger;
|
||||
private readonly TimeSpan dnsOKTimeout = TimeSpan.FromSeconds(60d);
|
||||
|
||||
/// <summary>
|
||||
/// DnscryptProxy后台服务
|
||||
@ -50,7 +49,6 @@ namespace FastGithub.DnscryptProxy
|
||||
{
|
||||
process.EnableRaisingEvents = true;
|
||||
process.Exited += this.OnProcessExit;
|
||||
await this.WaitForDnsOKAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -59,31 +57,6 @@ namespace FastGithub.DnscryptProxy
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待dns服务初始化
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task WaitForDnsOKAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
this.logger.LogInformation($"{this.dnscryptProxyService}正在初始化");
|
||||
using var timeoutTokenSource = new CancellationTokenSource(this.dnsOKTimeout);
|
||||
|
||||
try
|
||||
{
|
||||
using var linkeTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token);
|
||||
await this.dnscryptProxyService.WaitForDnsOKAsync(linkeTokenSource.Token);
|
||||
this.logger.LogInformation($"{this.dnscryptProxyService}初始化完成");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (timeoutTokenSource.IsCancellationRequested)
|
||||
{
|
||||
this.logger.LogWarning($"{this.dnscryptProxyService}在{this.dnsOKTimeout.TotalSeconds}秒内未能初始化完成");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进程退出时
|
||||
/// </summary>
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using DNS.Client;
|
||||
using DNS.Protocol;
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -14,7 +12,6 @@ namespace FastGithub.DnscryptProxy
|
||||
sealed class DnscryptProxyService
|
||||
{
|
||||
private const string name = "dnscrypt-proxy";
|
||||
private const string testDomain = "api.github.com";
|
||||
private readonly FastGithubConfig fastGithubConfig;
|
||||
|
||||
/// <summary>
|
||||
@ -65,62 +62,6 @@ namespace FastGithub.DnscryptProxy
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待dns服务OK
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task WaitForDnsOKAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var process = this.Process;
|
||||
if (process == null || process.HasExited || this.ControllState != ControllState.Started)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var processExitTokenSource = new CancellationTokenSource();
|
||||
process.EnableRaisingEvents = true;
|
||||
process.Exited += OnProcessExited;
|
||||
|
||||
try
|
||||
{
|
||||
using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, processExitTokenSource.Token);
|
||||
await this.WaitForDnsOKCoreAsync(linkedTokenSource.Token);
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.Exited -= OnProcessExited;
|
||||
}
|
||||
|
||||
void OnProcessExited(object? sender, EventArgs eventArgs)
|
||||
{
|
||||
processExitTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待dns服务OK
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task WaitForDnsOKCoreAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1d));
|
||||
using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token);
|
||||
var dnsClient = new DnsClient(this.fastGithubConfig.PureDns);
|
||||
await dnsClient.Lookup(testDomain, RecordType.A, linkedTokenSource.Token);
|
||||
break;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止dnscrypt-proxy
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DNS" Version="6.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
|
||||
<ProjectReference Include="..\FastGithub.Core\FastGithub.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -71,7 +71,7 @@ namespace FastGithub.ReverseProxy
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.logger.LogWarning($"由于{pureDns}解析{domain}失败,本次使用{fastDns}");
|
||||
this.logger.LogTrace($"由于{pureDns}解析{domain}失败,本次使用{fastDns}");
|
||||
return await LookupCoreAsync(fastDns, domain, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,6 @@ namespace FastGithub
|
||||
{
|
||||
return Host
|
||||
.CreateDefaultBuilder(args)
|
||||
.UseConsoleLifetime()
|
||||
.UseWindowsService()
|
||||
.UseBinaryPathContentRoot()
|
||||
.UseDefaultServiceProvider(c =>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user