连接超时时间10s
This commit is contained in:
parent
f193a5077c
commit
bb9a192f9d
@ -23,6 +23,7 @@ namespace FastGithub.Http
|
|||||||
{
|
{
|
||||||
private readonly DomainConfig domainConfig;
|
private readonly DomainConfig domainConfig;
|
||||||
private readonly IDomainResolver domainResolver;
|
private readonly IDomainResolver domainResolver;
|
||||||
|
private readonly TimeSpan connectTimeout = TimeSpan.FromSeconds(10d);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// HttpClientHandler
|
/// HttpClientHandler
|
||||||
@ -101,7 +102,14 @@ namespace FastGithub.Http
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await this.ConnectAsync(context, ipEndPoint, cancellationToken);
|
using var timeoutTokenSource = new CancellationTokenSource(this.connectTimeout);
|
||||||
|
using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutTokenSource.Token, cancellationToken);
|
||||||
|
return await this.ConnectAsync(context, ipEndPoint, linkedTokenSource.Token);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
innerExceptions.Add(new SocketException((int)SocketError.TimedOut));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user