Skip to content

Conversation

@halter73
Copy link
Member

@halter73 halter73 commented Sep 19, 2022

Description

Before this change, we had a whole suite of analyzers that were not being tested on the CI.

I just happened to be looking at these analyzers because we started working on new out-of-band analyzers for the hackathon. When running the tests locally, I discovered failing tests because of a false positive in our DetectMisplacedLambdaAttribute logic. That's when I realized these tests must not be running on the CI.

Customer Impact

Customers haven't noticed this. Below, the [Authorize] attribute is in the correct location, but we improperly warn anyway.

Inline false positive warning

But we've noticed that the false positive warning does not always show up in the error list. It appears to be due to the race condition fixed by dotnet/roslyn#6322. We think this might be why no customers have reported this issue. The false positive happens to be in a fairly specific case where an attribute is added to a lambda that then immediately invokes another method.

Build output and error list

Regression?

  • Yes
  • No

Tests haven't been running on the CI, so the regression likely happened sometime between preview1 when the analyzer was first released and now.

Risk

  • High
  • Medium
  • Low

I think it would be higher risk to continue running no tests for these analyzers in our release/7.0 branch.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@ghost ghost added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Sep 19, 2022
@halter73 halter73 force-pushed the halter73/7.0/fix-analyzers branch from c9f7a9b to ccfd9ab Compare September 19, 2022 16:51

static IMethodSymbol? GetReturnedInvocation(IBlockOperation blockOperation)
{
foreach (var op in blockOperation.ChildOperations.Reverse())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we search the child operations in reverse here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it made sense to search from the end of the method for return operations instead of the start because I'd expect most returns to be nearer to the end. Multiple return operations are an edge case this analyzer never really accounted for anyway.

@halter73 halter73 marked this pull request as ready for review September 19, 2022 23:58
@halter73 halter73 requested review from a team, Pilchie, dougbu and wtgodbe as code owners September 19, 2022 23:58
@halter73 halter73 marked this pull request as draft September 20, 2022 00:00
@halter73
Copy link
Member Author

I want to manually see if the analyzer is broken in our rc2 nightlies before undrafting this considering this PR targets release/7.0. If the analyzers just don't run rather than emit false positives, it might not be worth fixing. If we are emitting false positives like it was in the tests, we should probably send this through tactics.

@halter73
Copy link
Member Author

There appears to be a real issue with analyzer creating some false positives, but we think it has not been reported because of dotnet/roslyn#63225. Below, the [Authorize] attribute is in the correct location, but we improperly warn anyway.

Inline false positive warning

We've noticed that the false positive warning does not always show up in the error list:

Build output and error list

I've also noticed that our tests run with an outdated version of Microsoft.CodeAnalysis.CSharp compared to VS 17.4.0 Preview 2.0. Our tests run against 4.200.22.12801 and VS 17.4.0 Preview 2.0 loads 4.400.22.43014. Is this expected because it needs to work with 17.3 or something? Are we worried about incompatibilities? @dotnet/aspnet-build @jaredpar

@dotnet/minimal-apis What do we think about bringing this to tactics for rc2 or GA?

@halter73 halter73 marked this pull request as ready for review September 20, 2022 18:48
@halter73 halter73 added the Servicing-consider Shiproom approval is required for the issue label Sep 20, 2022
@ghost
Copy link

ghost commented Sep 20, 2022

Hi @halter73. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

@jaredpar
Copy link
Member

Are we worried about incompatibilities?

There shouldn't be any incompatibilities I'm aware of.

@halter73 halter73 added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Sep 21, 2022
@halter73
Copy link
Member Author

@dotnet/aspnet-admins This has been approved by tactics.

Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo changes to Build.props please

@halter73
Copy link
Member Author

@dougbu The point of the Build.props change was to run the tests that were previously not being run on the CI. This is the most important part of the fix, so I cannot just undo it.

I've updated it to only add Microsoft.AspNetCore.App.Analyzers.Test.csproj to Build.props rather than adding all the projects in the AspNetCoreAnalyzers directory since the non-test projects are already included by Microsoft.AspNetCore.App.Ref.csproj. Does this address your concern?

@dougbu
Copy link
Contributor

dougbu commented Sep 22, 2022

Does this address your concern?

Yes. I'll enable auto-merge (squash).


@SteveSandersonMS CircuitGracefulTerminationTests.ClosingTheBrowserWindow_GracefullyDisconnects_TheCurrentCircuit is failing in this attempt and I'm sure (a) that's not related to @halter73's change and (b) I've seen the same aspnet-components-e2e failure in other PRs and maybe rolling builds. Could you please quarantine this test❔

@dougbu dougbu enabled auto-merge (squash) September 22, 2022 00:41
@halter73
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@dougbu dougbu merged commit 5195e68 into release/7.0 Sep 23, 2022
@dougbu dougbu deleted the halter73/7.0/fix-analyzers branch September 23, 2022 01:04
JamesNK pushed a commit that referenced this pull request Sep 23, 2022
* Fix DetectMisplacedLambdaAttribute analyzer and tests
* Add AspNetCoreAnalyzers to Build.props
* Update eng/Build.props
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants