Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Fix DiagnosticSource to work with NativeAOT #78532

Merged
merged 10 commits into from
Jan 4, 2023

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Nov 18, 2022

Backport of #76109 to release/7.0

/cc @MichalStrehovsky @eerhardt

Customer Impact

Right now some extremely common code paths (i.e. HttpClient) report AOT warnings. Reported issues include:

This warning is confusing to customers because it is in our internal library code, and it is not possible for the customer to address the warning.

In late 7.0 we pushed out a change that disables EventSource on NativeAOT by default. We did this because DiagnosticSource (built on top of EventSource) was not AOT safe and if DiagnosticSource codepaths got activated (due to e.g. a machine-wide PerfView session), DiagnosticSource would cause the app to crash.

The current situation is that:

  • If someone wants to use DiagnosticSource, they need to opt into it in their project file and apply RD.XML workarounds to the AOT unsafe code in it.
  • If DiagnosticSource is included in the app in any way, it generates AOT safety warnings because the code is marked as AOT unsafe (the actual AOT unsafe implementation details never get activated though, unless the user opted in).

We got feedback about both of these aspects

With this change that DiagnosticSource no longer requires dynamic code (allowing it to work in a NativeAOT'd app). The change has been in main for 6 weeks, merges cleanly to 7.0, and addresses both of those aspects. Trimming problems may still occur (and trimming warnings will appear as appropriate), but are less common since the most common uses of DiagnosticSource have been manually preserved.

Testing

All NativeAOT testing. This change has been in main for 6 weeks. There are new AOT tests being added that ensure this scenario works.

Risk

Fairly low. The behavior change is limited to when "Dynamic Code" isn't support (i.e. NativeAOT), and when the Type being reflected upon is a ValueType. For "normal" .NET Apps there is no behavior change.

There were 2 problems:

1. The use of MakeGenericType doesn't work when a property is a ValueType.
An app will crash when a listener is enabled and DiagnosticSourceEventSource tries
writing values.
2. The properties on KeyValuePair were not being preserved correctly, so the Arguments
of the DiagnosticSourceEventSource methods were not being serialized correctly.

Add test (and infrastructure) to ensure DiagnosticSource works in a NativeAOT app

Fix #75945
- Only run them in Release configuration
- Suppress IL2026 warning
Set EventSourceSupport only on the projects that need it.
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Nov 18, 2022

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #76109 to release/7.0

/cc @MichalStrehovsky @eerhardt

Customer Impact

Testing

Risk

IMPORTANT: Is this backport for a servicing release? If so and this change touches code that ships in a NuGet package, please make certain that you have added any necessary package authoring and gotten it explicitly reviewed.

Author: github-actions[bot]
Assignees: -
Labels:

area-System.Diagnostics.Tracing, new-api-needs-documentation

Milestone: -

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Nov 18, 2022

@eerhardt @noahfalk any opinion on backporting this to 7.0? The AOT unsafety warning is not a great user experience. Making DiagnosticSource work is an added bonus.

But I don't know if this is going to meet the bar - I didn't ask for approvals yet, just to see how the CI fares and whether this can be backported cleanly.

Or we could just wait for more customer feedback on DiagnosticSource like I wrote in #76109 (comment). People wanting to use DiagnosticSource is more likely to meet the bar.

@MichalStrehovsky
Copy link
Member

(The issue in question with the warning is #78367)

@eerhardt
Copy link
Member

any opinion on backporting this to 7.0?

I'm supportive of backporting it. We already have 2 instances of customers bumping into this (one was trying to profile their NativeAOT application and the app crashing, and now the warning that customers can't do anything about).

Notes on backporting:

  1. We will need to do servicing packaging work - https://github.com/dotnet/runtime/blob/main/docs/project/library-servicing.md
  2. This is changing a ref file that ships in Microsoft.NETCore.App. (yes, it is just removing an attribute, but it is still a ref change) I'm not sure if the creation of a new "ref pack" is automatic or not. Or if manual work is needed for that kind of change. @ViktorHofer or @carlossanlop should know.

@ViktorHofer
Copy link
Member

This is changing a ref file that ships in Microsoft.NETCore.App. (yes, it is just removing an attribute, but it is still a ref change) I'm not sure if the creation of a new "ref pack" is automatic or not. Or if manual work is needed for that kind of change. @ViktorHofer or @carlossanlop should know.

These days with source analyzers being part of the targeting pack, it ships automatically with every release, i.e. here you can see the Microsoft.NETCore.App.Ref nuget package shipped during .NET 6 with every release:

image

@ViktorHofer
Copy link
Member

@MichalStrehovsky @eerhardt I added the required package servicing changes as described here for you.

@agocke
Copy link
Member

agocke commented Nov 18, 2022

@eerhardt Could you fill in the Risk section? This looks low risk to me since it keeps the old code path when not using AOT, but I'd like your take.

@carlossanlop
Copy link
Member

carlossanlop commented Nov 21, 2022

@MichalStrehovsky @eerhardt Besides the request to fill out the risk section and verifying the CI failures, is there anything else to address? Otherwise, can you please add the servicing-consider label and send an email to Tactics requesting approval?

I ask because for the January release, we will only have a one day window to merge servicing PRs, so I want to make sure all the PRs are 100% ready on that day for me to just click the merge button. That window is from Nov. 29th to Nov. 30th.

@eerhardt
Copy link
Member

eerhardt commented Nov 22, 2022

I've filled out the Risk section.

It appears the Libraries Build windows net48 x86 Release leg is failing due to the bump in AssemblyVersion. I haven't fully investigated, but it looks just like #77988 (comment). This will need to be addressed before we can merge.

cc @joperezr @ViktorHofer @ericstj

@MichalStrehovsky MichalStrehovsky added the Servicing-consider Issue for next servicing release review label Nov 22, 2022
@ViktorHofer
Copy link
Member

ViktorHofer commented Nov 22, 2022

It appears the Libraries Build windows net48 x86 Release leg is failing due to the bump in AssemblyVersion. I haven't fully investigated, but it looks just like #77988 (comment). This will need to be addressed before we can merge.

On it. I will send a PR today that will target main. Let's backport the fix after it got some validation in main.

@jeffschwMSFT jeffschwMSFT removed the Servicing-consider Issue for next servicing release review label Nov 22, 2022
ViktorHofer added a commit to ViktorHofer/runtime that referenced this pull request Nov 22, 2022
Manual backport of c8503d3
Fixes dotnet#77988
Unblocks dotnet#78532

Introduce the AnnotateTargetPathWithContract switch to
make it configure-able when a source project should
return the reference project's assembly instead of
the source assembly, when other projects compile
against it. Set it so that reference assemblies are
only returned for NetCoreAppCurrent tfms or when the
project isn't packable.

- Fix System.DirectoryServices.AccountManagement build
System.DirectoryServices.AccountManagement now builds against
src/System.DirectoryServices instead of ref/System.DirectoryServices
(because the package doesn't contain the ref assembly).

Because of that, the compiler now gets confused because of the
System.DirectoryServices.Interop namespace and the global Interop class.
This happens even though the DirectoryServices.Interop namespace doesn't include any
public types.

That results in the following errors:

src\libraries\System.DirectoryServices.AccountManagement\src\System\DirectoryServices\AccountManagement\AD\SidList.cs(50,26): error CS0246: The type or namespace name 'SID_AND_ATTRIBUTES' could not be found (are you missing a using directive or an assembly reference?)
src\libraries\System.DirectoryServices.AccountManagement\src\System\DirectoryServices\AccountManagement\interopt.cs(439,20): error CS0246: The type or namespace name 'UNICODE_INTPTR_STRING' could not be found (are you missing a using directive or an assembly reference?)
This commit fixes that by removing the System.DirectoryServices.Interop
namespace and moving the types into the parent namespace.

- Suppress nullable warnings in Serialization.Schema
Now that Schema compiles against the source assembly of System.CodeDom,
it receives nullability errors. I'm suppressing them manually for now
but am filing an issue to correctly fix those.

Related: dotnet#78036
@ViktorHofer ViktorHofer added Servicing-consider Issue for next servicing release review and removed new-api-needs-documentation labels Nov 24, 2022
@eerhardt
Copy link
Member

CI failure is #78778.

@carlossanlop
Copy link
Member

@MichalStrehovsky can you please sign-off?
@eerhardt did you send an email to Tactics already? I can't find one. If not, please send it. The window for merging backports this release is going to be of just one day (29-30 Nov), so I'd like to make sure all PRs are ready for me to just hit merge.

@jeffschwMSFT jeffschwMSFT modified the milestones: 7.0.2, 7.0.x Nov 29, 2022
Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

approved. we will take for consideration in 7.0.x

@tommcdon tommcdon modified the milestones: 7.0.x, 7.0.3 Nov 29, 2022
@jeffschwMSFT jeffschwMSFT modified the milestones: 7.0.3, 7.0.x Dec 6, 2022
@rbhanda rbhanda modified the milestones: 7.0.x, 7.0.3 Dec 6, 2022
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Dec 6, 2022
@ericstj
Copy link
Member

ericstj commented Dec 6, 2022

A note for servicing validation of this - we should make sure we get the updates to the reference assembly in the 7.0 ref pack, and that the same fixes are present in the nuget package.

@carlossanlop
Copy link
Member

Signed-off by area owners.
OOB package authoring changes included (pending validation when the coherent build is released).
CI failure seems unrelated to this change.
Approved by Tactics.
7.0.3 Milestone applied.
Ready to merge. :shipit:

@carlossanlop carlossanlop merged commit 814af26 into release/7.0 Jan 4, 2023
@carlossanlop carlossanlop deleted the backport/pr-76109-to-release/7.0 branch January 4, 2023 20:12
@ghost ghost locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants