Skip to content

Commit 97db104

Browse files
authored
Suppress existing violations for S4462 and turn the rule on (#1553)
1 parent b8b9597 commit 97db104

File tree

7 files changed

+26
-2
lines changed

7 files changed

+26
-2
lines changed

Steeltoe.Debug.ruleset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<Rule Id="S4277" Action="None" />
108108
<Rule Id="S4428" Action="None" />
109109
<Rule Id="S4433" Action="None" />
110+
<Rule Id="S4462" Action="Warning" />
110111
<Rule Id="S4487" Action="Info" />
111112
<Rule Id="S4583" Action="None" />
112113
<Rule Id="S4663" Action="Info" />

Steeltoe.Release.ruleset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<Rule Id="S4277" Action="None" />
9595
<Rule Id="S4428" Action="None" />
9696
<Rule Id="S4433" Action="None" />
97+
<Rule Id="S4462" Action="Warning" />
9798
<Rule Id="S4583" Action="None" />
9899
<Rule Id="S6354" Action="Warning" />
99100
<Rule Id="S6419" Action="None" />

src/Configuration/src/ConfigServer/ConfigServerConfigurationProvider.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ private void OnSettingsChanged()
132132
{
133133
if (_refreshTimer == null)
134134
{
135+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
136+
// Justification: Configuration sources and providers don't support async.
135137
_refreshTimer = new Timer(_ => DoPolledLoadAsync().GetAwaiter().GetResult(), null, TimeSpan.Zero, ClientOptions.PollingInterval);
138+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
136139
}
137140
else if (existingPollingInterval != ClientOptions.PollingInterval)
138141
{
@@ -197,7 +200,10 @@ private async Task DoPolledLoadAsync()
197200
/// </summary>
198201
public override void Load()
199202
{
203+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
204+
// Justification: Configuration sources and providers don't support async.
200205
LoadInternalAsync(true, CancellationToken.None).GetAwaiter().GetResult();
206+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
201207
}
202208

203209
internal async Task<ConfigEnvironment?> LoadInternalAsync(bool updateDictionary, CancellationToken cancellationToken)
@@ -695,8 +701,11 @@ private void AddPropertySource(PropertySource? source, Dictionary<string, string
695701

696702
private void RenewToken()
697703
{
704+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
705+
// Justification: Configuration sources and providers don't support async.
698706
_ = new Timer(_ => RefreshVaultTokenAsync(CancellationToken.None).GetAwaiter().GetResult(), null,
699707
TimeSpan.FromMilliseconds(ClientOptions.TokenRenewRate), TimeSpan.FromMilliseconds(ClientOptions.TokenRenewRate));
708+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
700709
}
701710

702711
// fire and forget

src/Discovery/src/Consul/ConsulDiscoveryClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public ConsulDiscoveryClient(IConsulClient client, IOptionsMonitor<ConsulDiscove
5454
_thisServiceInstance = new ThisServiceInstance(registrar.Registration);
5555
_registrar = registrar;
5656

57+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
58+
// Justification: Async calls from a constructor are not possible. To fix this, an alternate design is needed.
5759
_registrar.StartAsync(CancellationToken.None).GetAwaiter().GetResult();
60+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
5861
}
5962

6063
private static ConsulServiceRegistrar CreateRegistrar(IConsulClient client, IOptionsMonitor<ConsulDiscoveryOptions> optionsMonitor,

src/Discovery/src/Eureka/EurekaDiscoveryClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ public EurekaDiscoveryClient(EurekaApplicationInfoManager appInfoManager, Eureka
107107
try
108108
{
109109
// Only register when periodically refreshing. Just once at startup doesn't make sense.
110+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
111+
// Justification: Async calls from a constructor are not possible. To fix this, an alternate design is needed.
110112
RegisterAsync(false, CancellationToken.None).GetAwaiter().GetResult();
113+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
111114
}
112115
catch (Exception exception)
113116
{
@@ -125,7 +128,10 @@ public EurekaDiscoveryClient(EurekaApplicationInfoManager appInfoManager, Eureka
125128
{
126129
try
127130
{
131+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
132+
// Justification: Async calls from a constructor are not possible. To fix this, an alternate design is needed.
128133
FetchRegistryAsync(true, CancellationToken.None).GetAwaiter().GetResult();
134+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
129135
}
130136
catch (Exception exception)
131137
{

src/Security/src/Authentication.JwtBearer/TokenKeyResolver.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ internal SecurityKey[] ResolveSigningKey(string keyId)
3737
return [resolved];
3838
}
3939

40-
// can't be async all the way until updates are complete in Microsoft libraries
40+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
41+
// Justification: can't be async all the way until updates are complete in Microsoft libraries
4142
// https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/468
4243
JsonWebKeySet? keySet = FetchKeySetAsync(CancellationToken.None).GetAwaiter().GetResult();
44+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
4345

4446
if (keySet != null)
4547
{

src/Security/src/Authentication.OpenIdConnect/TokenKeyResolver.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ internal SecurityKey[] ResolveSigningKey(string keyId)
3737
return [resolved];
3838
}
3939

40-
// can't be async all the way until updates are complete in Microsoft libraries
40+
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
41+
// Justification: can't be async all the way until updates are complete in Microsoft libraries
4142
// https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/468
4243
JsonWebKeySet? keySet = FetchKeySetAsync(CancellationToken.None).GetAwaiter().GetResult();
44+
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
4345

4446
if (keySet != null)
4547
{

0 commit comments

Comments
 (0)