Skip to content

Commit

Permalink
ignore some exception when cancelled. add tfm net6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stratosblue committed Mar 15, 2022
1 parent 1d38c0e commit d2f6256
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/PublishNugetPackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1.8.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: restore dependencies
run: dotnet restore
- name: build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ private static NacosConfigurationSource CreateNacosConfigurationSource(INacosCon
return new NacosConfigurationSource(new NacosConfigurationProviderOptions(client, descriptor, parsersCopy, loggerFactory));
}

#if NET5_0

private static IConfigurationSection GetRequiredSection(this IConfiguration configuration, string sectionName)
{
if (!configuration.TryGetSection(sectionName, out var configurationSection))
Expand All @@ -252,6 +254,8 @@ private static IConfigurationSection GetRequiredSection(this IConfiguration conf
return configurationSection;
}

#endif

private static INacosConfigurationBuilder InternalAddNacos(this IConfigurationBuilder builder, Action<NacosConfigurationSourceOptions> setupAction, IConfiguration? configuration = null)
{
if (builder is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ private Task OnConfigurationChangeAsync(NacosConfigurationDescriptor descriptor,
}
catch (Exception ex)
{
token.ThrowIfCancellationRequested();

_logger?.LogError(ex, "加载变更配置失败 {0}", _descriptor);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand All @@ -24,6 +24,10 @@
<GrpcVersion>2.*</GrpcVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<McrVersion>6.0.*</McrVersion>
</PropertyGroup>

<!--SourceLink-->
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Nacos.Grpc/NacosGrpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private async Task<NacosResponse> InternalRequestAsync(NacosRequest request, Nac

Logger?.LogDebugSendPayload(requestPayload);

var responsePayload = await transportClient.RequestAsync(requestPayload, cancellationToken: token);
var responsePayload = await transportClient.RequestAsync(requestPayload, cancellationToken: token).ConfigureAwait(false);

Logger?.LogDebugReceivePayload(responsePayload);

Expand Down
4 changes: 4 additions & 0 deletions src/Nacos/AccessTokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ private async Task<LoginResponse> LoginAsync(CancellationToken token = default)
}
catch (Exception ex)
{
token.ThrowIfCancellationRequested();

_logger?.LogError(ex, "请求执行失败 {0} - TargetServer: {1}", loginRequest, server);
_serverAddressAccessor.MoveNextAddress();
continue;
Expand Down Expand Up @@ -203,6 +205,8 @@ private void StartAutoTokenRefresh(int tokenTtl)
}
catch (Exception ex)
{
cancellationToken.ThrowIfCancellationRequested();
failCount++;
var retryDelaySeconds = failCount > 12 ? 120 : failCount * 10;
_logger?.LogError(ex, "自动刷新AccessToken出现异常,等待 {0} s 后再次进行尝试", retryDelaySeconds);
Expand Down
2 changes: 2 additions & 0 deletions src/Nacos/Http/NacosConfigurationHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ private async Task PollingListeningConfigurationAsync(NacosConfigurationDescript
}
catch (Exception ex)
{
token.ThrowIfCancellationRequested();

//HACK 是否需要异常处理
Logger?.LogError(ex, "配置变更订阅处理异常, 变更信息: {0}", newDescriptor);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Nacos/Http/NacosHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public virtual async Task InitAsync()
}
catch (Exception ex)
{
token.ThrowIfCancellationRequested();

Logger?.LogError(ex, "请求执行失败 {0} - TargetServer: {1}", request, server);

_serverAddressAccessor.MoveNextAddress();
Expand Down
2 changes: 2 additions & 0 deletions src/Nacos/RemoteServerAddressAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ private async Task<Uri[]> GetServerUrisFromAcsEndpointAsync(CancellationToken to
}
catch (Exception ex)
{
token.ThrowIfCancellationRequested();

if (i == 2)
{
break;
Expand Down
2 changes: 1 addition & 1 deletion src/extensions.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionPrefix>1.0.1</VersionPrefix>

<IsPackable>true</IsPackable>

Expand Down

0 comments on commit d2f6256

Please sign in to comment.