sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

Fix S2342 FP: Flaky reports

Open bart-vmware opened this issue 1 year ago • 2 comments

Description

During ci-build, we randomly get build errors such as the following:

error S2342: Rename this enumeration to match the regular expression: '^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$'

The affected [Flags] enum is named FastTestConfigurations, which complies with the rule. Because we sometimes get this error, but not always, I suspect a static regex is being used that isn't thread-safe.

[Flags]
public enum FastTestConfigurations
{
    ConfigServer = 1,
    Discovery = 2,
    Connectors = 4,
    WaveFrontExport = 8,
    All = ConfigServer | Discovery | Connectors | WaveFrontExport
}

Repro steps

Not available, it happens randomly, but not always. I've seen this multiple times in Azure DevOps, running on Ubuntu against .NET 8. I haven't experienced it locally on Windows 11.

Known workarounds

Restart the cibuild, which usually makes the error go away.

Related information

  • C#/VB.NET Plugins version: 9.25.1.91650
  • Visual Studio version: 17.11.5
  • MSBuild / dotnet version: .NET 8
  • SonarScanner for .NET version (if used): N/A
  • Operating System: Ubuntu

bart-vmware avatar Oct 10 '24 11:10 bart-vmware

Hey there, This is an interesting problem. Since it is flaky, I am not sure how to investigate it.

Can you clarify what you mean by this?

Because we sometimes get this error, but not always, I suspect a static regex is being used that isn't thread-safe

Yeah, these things are usually hard to diagnose. I was just guessing, without looking at the source code. It may as well be a race condition somewhere in Sonar code or the underlying compiler.

The project where this happens is open-source under the .NET Foundation. Sources are at https://github.com/SteeltoeOSS/Steeltoe. I've tried to dig up a build log, but couldn't find it back in the large amount of builds. I'll post it here when it happens again.

bart-vmware avatar Oct 14 '24 13:10 bart-vmware

This issue popped up again on Friday during this run on a Microsoft-hosted MacOS pipeline, here is the output from the failed step:

2025-02-07T16:22:36.5315990Z ##[section]Starting: dotnet build
2025-02-07T16:22:36.5325350Z ==============================================================================
2025-02-07T16:22:36.5325750Z Task         : .NET Core
2025-02-07T16:22:36.5325960Z Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2025-02-07T16:22:36.5326280Z Version      : 2.247.3
2025-02-07T16:22:36.5326490Z Author       : Microsoft Corporation
2025-02-07T16:22:36.5326630Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2025-02-07T16:22:36.5326970Z ==============================================================================
2025-02-07T16:22:36.8894620Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2025-02-07T16:22:36.8942820Z [command]/Users/runner/hostedtoolcache/dotnet/dotnet build /Users/runner/work/1/s/src/Steeltoe.Management.slnf -dl:CentralLogger,"/Users/runner/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.247.3/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/Users/runner/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.247.3/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" --no-restore -c Release -v minimal
2025-02-07T16:22:46.8462090Z   ConfigurationSchemaGenerator -> /Users/runner/work/1/s/src/Tools/src/ConfigurationSchemaGenerator/bin/Release/net8.0/ConfigurationSchemaGenerator.dll
2025-02-07T16:22:54.5932250Z ##[error]src/Common/test/TestResources/FastTestConfigurations.cs(8,13): Error S2342: Rename this enumeration to match the regular expression: '^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$'. (https://rules.sonarsource.com/csharp/RSPEC-2342)
2025-02-07T16:22:54.6946760Z /Users/runner/work/1/s/src/Common/test/TestResources/FastTestConfigurations.cs(8,13): error S2342: Rename this enumeration to match the regular expression: '^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$'. (https://rules.sonarsource.com/csharp/RSPEC-2342) [/Users/runner/work/1/s/src/Common/test/TestResources/Steeltoe.Common.TestResources.csproj]
2025-02-07T16:22:56.3910270Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Common
2025-02-07T16:22:57.1309510Z   Steeltoe.Common -> /Users/runner/work/1/s/src/Common/src/Common/bin/Release/net8.0/Steeltoe.Common.dll
2025-02-07T16:22:57.3535550Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Common/bin/Release/Steeltoe.Common.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:22:57.3589370Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Common/bin/Release/Steeltoe.Common.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:01.1568110Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Configuration.Abstractions
2025-02-07T16:23:01.5404410Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Common.Certificates
2025-02-07T16:23:02.3982440Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Common.Hosting
2025-02-07T16:23:02.4207370Z   Steeltoe.Configuration.Abstractions -> /Users/runner/work/1/s/src/Configuration/src/Abstractions/bin/Release/net8.0/Steeltoe.Configuration.Abstractions.dll
2025-02-07T16:23:03.9238030Z   Steeltoe.Common.Certificates -> /Users/runner/work/1/s/src/Common/src/Certificates/bin/Release/net8.0/Steeltoe.Common.Certificates.dll
2025-02-07T16:23:03.9440230Z   Steeltoe.Common.Hosting -> /Users/runner/work/1/s/src/Common/src/Hosting/bin/Release/net8.0/Steeltoe.Common.Hosting.dll
2025-02-07T16:23:05.1116910Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Configuration.Placeholder
2025-02-07T16:23:06.3179050Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Management.Abstractions
2025-02-07T16:23:06.5970760Z   Steeltoe.Configuration.Placeholder -> /Users/runner/work/1/s/src/Configuration/src/Placeholder/bin/Release/net8.0/Steeltoe.Configuration.Placeholder.dll
2025-02-07T16:23:06.6455770Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Management.Tasks
2025-02-07T16:23:07.2198870Z   Steeltoe.Management.Abstractions -> /Users/runner/work/1/s/src/Management/src/Abstractions/bin/Release/net8.0/Steeltoe.Management.Abstractions.dll
2025-02-07T16:23:08.7786040Z   Successfully created package '/Users/runner/work/1/s/src/Configuration/src/Abstractions/bin/Release/Steeltoe.Configuration.Abstractions.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:09.6527310Z   Successfully created package '/Users/runner/work/1/s/src/Configuration/src/Abstractions/bin/Release/Steeltoe.Configuration.Abstractions.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:10.2564990Z   Steeltoe.Management.Tasks -> /Users/runner/work/1/s/src/Management/src/Tasks/bin/Release/net8.0/Steeltoe.Management.Tasks.dll
2025-02-07T16:23:11.1997540Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Hosting/bin/Release/Steeltoe.Common.Hosting.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:11.1998920Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Hosting/bin/Release/Steeltoe.Common.Hosting.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:11.3003980Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Abstractions/bin/Release/Steeltoe.Management.Abstractions.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:11.4007500Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Abstractions/bin/Release/Steeltoe.Management.Abstractions.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:11.5011980Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Logging.Abstractions
2025-02-07T16:23:11.6427460Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Common.Http
2025-02-07T16:23:11.6544240Z   Steeltoe.Logging.Abstractions -> /Users/runner/work/1/s/src/Logging/src/Abstractions/bin/Release/net8.0/Steeltoe.Logging.Abstractions.dll
2025-02-07T16:23:11.6697580Z   Steeltoe.Common.Http -> /Users/runner/work/1/s/src/Common/src/Http/bin/Release/net8.0/Steeltoe.Common.Http.dll
2025-02-07T16:23:11.8618700Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Tasks/bin/Release/Steeltoe.Management.Tasks.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:12.1069620Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Tasks/bin/Release/Steeltoe.Management.Tasks.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:12.2367470Z   Successfully created package '/Users/runner/work/1/s/src/Configuration/src/Placeholder/bin/Release/Steeltoe.Configuration.Placeholder.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:12.2805880Z   Successfully created package '/Users/runner/work/1/s/src/Configuration/src/Placeholder/bin/Release/Steeltoe.Configuration.Placeholder.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:12.6254590Z   Successfully created package '/Users/runner/work/1/s/src/Logging/src/Abstractions/bin/Release/Steeltoe.Logging.Abstractions.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:12.7776180Z   Successfully created package '/Users/runner/work/1/s/src/Logging/src/Abstractions/bin/Release/Steeltoe.Logging.Abstractions.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:13.2447950Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Configuration.CloudFoundry
2025-02-07T16:23:14.1565810Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Common.Logging
2025-02-07T16:23:15.0680070Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Logging.DynamicLogger
2025-02-07T16:23:15.9298900Z   Steeltoe.Logging.DynamicLogger -> /Users/runner/work/1/s/src/Logging/src/DynamicLogger/bin/Release/net8.0/Steeltoe.Logging.DynamicLogger.dll
2025-02-07T16:23:15.9737200Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Logging.DynamicSerilog
2025-02-07T16:23:18.1470140Z   Steeltoe.Configuration.CloudFoundry -> /Users/runner/work/1/s/src/Configuration/src/CloudFoundry/bin/Release/net8.0/Steeltoe.Configuration.CloudFoundry.dll
2025-02-07T16:23:18.3890700Z   Steeltoe.Logging.DynamicSerilog -> /Users/runner/work/1/s/src/Logging/src/DynamicSerilog/bin/Release/net8.0/Steeltoe.Logging.DynamicSerilog.dll
2025-02-07T16:23:18.4890250Z   Successfully created package '/Users/runner/work/1/s/src/Logging/src/DynamicLogger/bin/Release/Steeltoe.Logging.DynamicLogger.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:18.5404830Z   Successfully created package '/Users/runner/work/1/s/src/Logging/src/DynamicLogger/bin/Release/Steeltoe.Logging.DynamicLogger.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:18.6970230Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Configuration.Encryption
2025-02-07T16:23:18.7870540Z   Successfully created package '/Users/runner/work/1/s/src/Logging/src/DynamicSerilog/bin/Release/Steeltoe.Logging.DynamicSerilog.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:18.7932800Z   Successfully created package '/Users/runner/work/1/s/src/Logging/src/DynamicSerilog/bin/Release/Steeltoe.Logging.DynamicSerilog.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:19.8598830Z   Successfully created package '/Users/runner/work/1/s/src/Configuration/src/CloudFoundry/bin/Release/Steeltoe.Configuration.CloudFoundry.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:19.9372570Z   Successfully created package '/Users/runner/work/1/s/src/Configuration/src/CloudFoundry/bin/Release/Steeltoe.Configuration.CloudFoundry.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:20.4341670Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Http/bin/Release/Steeltoe.Common.Http.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:20.4396600Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Http/bin/Release/Steeltoe.Common.Http.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:20.4539690Z   Steeltoe.Common.Logging -> /Users/runner/work/1/s/src/Common/src/Logging/bin/Release/net8.0/Steeltoe.Common.Logging.dll
2025-02-07T16:23:20.4707770Z   Steeltoe.Configuration.Encryption -> /Users/runner/work/1/s/src/Configuration/src/Encryption/bin/Release/net8.0/Steeltoe.Configuration.Encryption.dll
2025-02-07T16:23:20.6383110Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Logging/bin/Release/Steeltoe.Common.Logging.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:20.6431380Z   Successfully created package '/Users/runner/work/1/s/src/Common/src/Logging/bin/Release/Steeltoe.Common.Logging.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:35.3540650Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Management.Endpoint
2025-02-07T16:23:36.4704770Z   Steeltoe.Management.Endpoint -> /Users/runner/work/1/s/src/Management/src/Endpoint/bin/Release/net8.0/Steeltoe.Management.Endpoint.dll
2025-02-07T16:23:38.0129700Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Management.Prometheus
2025-02-07T16:23:39.6552380Z   Running ConfigurationSchemaGenerator for project: Steeltoe.Management.Tracing
2025-02-07T16:23:40.6665270Z   Steeltoe.Management.Tracing -> /Users/runner/work/1/s/src/Management/src/Tracing/bin/Release/net8.0/Steeltoe.Management.Tracing.dll
2025-02-07T16:23:40.8542820Z   Steeltoe.Management.Prometheus -> /Users/runner/work/1/s/src/Management/src/Prometheus/bin/Release/net8.0/Steeltoe.Management.Prometheus.dll
2025-02-07T16:23:43.1124420Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Endpoint/bin/Release/Steeltoe.Management.Endpoint.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:43.1220250Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Endpoint/bin/Release/Steeltoe.Management.Endpoint.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:43.7047370Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Tracing/bin/Release/Steeltoe.Management.Tracing.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:43.7090600Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Tracing/bin/Release/Steeltoe.Management.Tracing.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:43.7220930Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Prometheus/bin/Release/Steeltoe.Management.Prometheus.4.0.566-alpha-g3ce339059e.nupkg'.
2025-02-07T16:23:43.7252620Z   Successfully created package '/Users/runner/work/1/s/src/Management/src/Prometheus/bin/Release/Steeltoe.Management.Prometheus.4.0.566-alpha-g3ce339059e.snupkg'.
2025-02-07T16:23:43.7934430Z 
2025-02-07T16:23:43.7964960Z Build FAILED.
2025-02-07T16:23:43.7966270Z 
2025-02-07T16:23:43.7970400Z /Users/runner/work/1/s/src/Common/test/TestResources/FastTestConfigurations.cs(8,13): error S2342: Rename this enumeration to match the regular expression: '^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$'. (https://rules.sonarsource.com/csharp/RSPEC-2342) [/Users/runner/work/1/s/src/Common/test/TestResources/Steeltoe.Common.TestResources.csproj]
2025-02-07T16:23:43.7972500Z     0 Warning(s)
2025-02-07T16:23:43.7974410Z     1 Error(s)
2025-02-07T16:23:43.7975860Z 
2025-02-07T16:23:43.7978030Z Time Elapsed 00:01:06.54
2025-02-07T16:23:43.8187420Z 
2025-02-07T16:23:43.8208270Z ##[error]Error: The process '/Users/runner/hostedtoolcache/dotnet/dotnet' failed with exit code 1
2025-02-07T16:23:43.8214010Z ##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
2025-02-07T16:23:43.8222770Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2025-02-07T16:23:43.8225780Z ##[error]Dotnet command failed with non-zero exit code on the following projects : [ '/Users/runner/work/1/s/src/Steeltoe.Management.slnf' ]
2025-02-07T16:23:43.8287370Z ##[section]Finishing: dotnet build

TimHess avatar Feb 10 '25 14:02 TimHess

Hello,

I looked into your project and it seems, that the error is raised when the ConfigurationSchemaGenerator.csproj project is build and/or run.

That project does it's own Roslyn based compilation here and raises its own issues, like here.

My suspicion is that during the compilation that takes place when ConfigurationSchemaGenerator is executed our analyzers run as well. This may lead to problems especially with parameterized rules (like S2342 where you can parameterize the regex used) but also in general because we orchestrate the build (e.g. to inject configuration into the analyzers). That orchestration is most likely not picked up correctly when another compilation is created by ConfigurationSchemaGenerator.

I would recommend to run ConfigurationSchemaGenerator outside of the sonar code analysis.

Note: I haven't studied what ConfigurationSchemaGenerator is and how it is used in your pipeline, so I may be wrong here. It would help, if you could shed some light on what ConfigurationSchemaGenerator is (it seems to be related to Aspire, right?).

Hi @martin-strecker-sonarsource, thanks for looking into this.

We maintain a copy of Aspire's generator because there's no NuGet package for it. It executes during build, producing a JSON schema file (that gets embedded in our output NuGet package) to enable IntelliSense in Visual Studio for appsettings.json files.

I don't think Sonar analyzers run during build of the tool, because it has no references to Sonar:

Image

I also don't think Sonar analyzers run when the tool executes (which is when other projects are built). You can verify by uncommenting the LAUNCH_DEBUGGER line in ConfigurationSchemaGenerator.csproj. Then rebuild project Steeltoe.Common and wait for the Just In Time Debugger (which can be installed using Visual Studio Installer) to pop up. Add a breakpoint in RootGenerateCommand.cs at the line:

ConfigSchemaGenerator.GenerateSchema(inputAssembly, references, outputFile);

Once the breakpoint is hit, the list of references does not include any Sonar assemblies. Disassembly of Steeltoe.Common (the inputAssembly variable) also doesn't contain any Sonar references:

Image

bart-vmware avatar Feb 11 '25 14:02 bart-vmware

Thank you for the clarifications. I looked into the other successful runs and it seems indeed unrelated to ConfigurationSchemaGenerator (it looks like the 'ConfigurationSchemaGenerator' isn't even run for the project Steeltoe.Common.TestResources).

I haven't found another failing build step here and I was wondering if the failure is specific to MacOS (you mentioned Ubuntu in the issue description but I haven't found a failing build there). Have you seen the same error in other builds on other platforms?

The background is that I have a hard time to understand what can possibly be flaky here. The RegEx looks as expected and the position in code found is correct.

Can you please also link to the pipeline yaml definition for these builds. It would also help if you could turn verbose mode on and send us the logs for a failed run:

- task: SonarCloudPrepare@3
    inputs:
      SonarCloud: 'sonarcloud'
      organization: 'foo'
      scannerMode: 'dotnet'
      projectKey: 'foo_sonar-scanning-someconsoleapp'
      projectName: 'sonar-scanning-someconsoleapp'
      extraProperties: |
        sonar.verbose=true

The important logs are in the END step (i.e. SonarCloudAnalyze / “Run Code Analysis”)

The build should also be executed with verbose logs:

dotnet build -v:d

Thank you.

The failure on Ubuntu was months ago, those logs have been cleaned up by now.

Pipeline yaml files are at https://github.com/SteeltoeOSS/Steeltoe/tree/main/build and https://github.com/SteeltoeOSS/Steeltoe/blob/main/azure-pipelines.yml.

What's the performance impact on activating verbose logging? Given the failure occurs only once every few months.

bart-vmware avatar Feb 12 '25 11:02 bart-vmware

Also, note the failures haven't occurred in the Sonar build pipeline so far, so we'd need verbose logging in all pipelines.

bart-vmware avatar Feb 12 '25 11:02 bart-vmware

I looked into the pipelines https://github.com/SteeltoeOSS/Steeltoe/blob/main/azure-pipelines.yml and https://github.com/SteeltoeOSS/Steeltoe/blob/main/build/sonar-analyze.yml The second one is ubuntu only and for the first one MacOS seems to be disabled at the moment. I can not find anything unusual in both pipelines. I would recommend enabling verbose logging for the pipeline that caused the biggest trouble in the past. The performance impact of the logging should be neglectable.

Also seeing this issue - let me know if I can provide any details that are helpful for diagnosis.

markuspalme avatar Mar 18 '25 08:03 markuspalme

@markuspalme Verbose logs would be very useful as described in https://github.com/SonarSource/sonar-dotnet/issues/9683#issuecomment-2651236313

It happened again today, this time on Ubuntu. Logs at https://dev.azure.com/SteeltoeOSS/Steeltoe/_build/results?buildId=30623&view=logs&j=d3006ae9-e0d8-51ca-f80d-b22532b69219&t=95ab65d7-e607-5531-bf1f-611160e7c133.

bart-vmware avatar Apr 14 '25 15:04 bart-vmware

It looks like this time it was on Windows, right? It happened on the Security_Windows stage and in the Install .Net x tasks the output says Detected platform (Primary): win-x64.

This an really odd issue because I don't see anything that may cause this problem on our side. I will add this issue to our current sprint and we will implement better "logging" by changing the issue message to

private const string MessageFormat = "Rename the enumeration '{0}' to match the regular expression: '{1}'.";

This may give us a better idea whether the regex is misbehaving or the syntax tree for the enum is broken.

Sorry, yes, Windows.

bart-vmware avatar Apr 15 '25 06:04 bart-vmware

Suggestion:

  • Add a temporary undocumented MSBuild property or environment variable that we can set from our Azure DevOps pipeline.
  • When set, double-check the failure using conventional logic, ie, with string.Contains, etc.
  • If the conventional logic indicates no failure, log as much as you can, in such a way that it appears in the build output.

bart-vmware avatar Apr 17 '25 10:04 bart-vmware

It looks like this problem is caused by a time-out in the regex. We use a timeout (as recommended here) for the regex and it seems that sometimes that timeout is hit. This might be due to the parsing and compilation of the regex on first use. We changed the fallback return value of IsMatch for this rule, so the rule does not raise in case of a time out (this causes a false negative, which we generally prefer over false positives) This is the PR with this fix: https://github.com/SonarSource/sonar-dotnet/commit/2f26af14e245c75a49a0324599194e4770f9ac9c It will be part of the next release.

Occasionally hitting the 100ms timeout on shared build agents is a reasonable assumption. I'm happy with this solution, thanks.

bart-vmware avatar Apr 24 '25 16:04 bart-vmware

Internal ticket NET-1538