Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Nov 14, 2023

Backport of #94602 to release/8.0-staging

/cc @ivanpovazan

Customer Impact

ASP.NET test suite uses GetCustomAttributes API with a custom attribute provider: https://github.com/dotnet/aspnetcore/blob/402e7fc10aa304775f50d318c8a4dafbf46dbfe0/src/Shared/PropertyAsParameterInfo.cs#L15 which was not properly supported by Mono causing about 100 failing tests, as reported here: #94437 (comment)

This affects customers using aspnetcore http request handling on platforms where Mono is the primary runtime flavor. This may also affect customers on mobile or WebAssembly.

This PR fixes the issue.

Testing

This PR includes a unit test which verifies the fix that should pass on CI.

Risk

Low.

IMPORTANT: If this backport is for a servicing release, please verify that:

  • The PR target branch is release/X.0-staging, not release/X.0.

  • If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.

@ghost
Copy link

ghost commented Nov 14, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #94602 to release/8.0-staging

/cc @ivanpovazan

Customer Impact

Testing

Risk

IMPORTANT: If this backport is for a servicing release, please verify that:

  • The PR target branch is release/X.0-staging, not release/X.0.

  • If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.

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

area-System.Reflection

Milestone: -

@lambdageek lambdageek added the Servicing-consider Issue for next servicing release review label Nov 14, 2023
@lambdageek lambdageek added this to the 8.0.x milestone Nov 14, 2023
@ivanpovazan
Copy link
Member

The added test has successfully passed on CI.

This is safe to be merged.

@carlossanlop
Copy link
Contributor

@ivanpovazan @lambdageek did this get Tactics approval? Today is code complete.

@carlossanlop
Copy link
Contributor

I'm flowing staging to internal now, so the branches are closed. This will have to wait until the January release.

@steveisok steveisok added Servicing-rejected and removed Servicing-consider Issue for next servicing release review labels Nov 21, 2023
@steveisok
Copy link
Member

Per tactics, this change unfortunately doesn't meet the bar in terms of customer impact. @ivanpovazan if you find this blocks customers in a significant way, please identify and reopen.

@steveisok steveisok closed this Nov 21, 2023
@tmds
Copy link
Member

tmds commented Nov 22, 2023

@steveisok This affects the ASP.NET Core request handling on RHEL builds of .NET for ppc64le and s390x.
It would be preferable to backport this upstream rather than Red Hat adding it as a patch in our builds.
Only backporting to .NET 8 is good for us.

@jkotas jkotas deleted the backport/pr-94602-to-release/8.0-staging branch November 27, 2023 15:31
@janani66
Copy link

I echo Tom's comments -- will be good to have it back ported to .NET 8

@jkotas
Copy link
Member

jkotas commented Dec 13, 2023

If you would like to see this backported, it needs to be justified by a concrete customer-centric statement. What is the concrete ASP.NET or Mobile scenario that is impacted by this issue? How likely is it for customers to hit the issue? Are there workarounds?

ASP.NET test suite failing is not a good justification for a backport. It is why the backport was rejected by tactics.

@ivanpovazan
Copy link
Member

I think one possible (and simple) workaround would be to intercept calling the parameterless extension method GetCustomAttributes by defining the parameterless variant of the method in the custom attribute provider it self https://github.com/dotnet/aspnetcore/blob/402e7fc10aa304775f50d318c8a4dafbf46dbfe0/src/Shared/PropertyAsParameterInfo.cs#L15

public object[] GetCustomAttributes() => GetCustomAttributes(true);

Explanation

If we take one of the tests that were reported as crashing:

  1. A test requests creating a delegate through RequestDelegateFactory https://github.com/dotnet/aspnetcore/blob/83947bf3bc084c8f6655c5cbd07d2f7bc2fbd928/src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs#L1184
  2. This ends up calling the extension method System.Reflection.CustomAttributeExtensions.GetCustomAttributes(this ParameterInfo element) on a custom ParameterInfo
    https://github.com/dotnet/aspnetcore/blob/83947bf3bc084c8f6655c5cbd07d2f7bc2fbd928/src/Http/Http.Extensions/src/RequestDelegateFactory.cs#L701
  3. The extension method further calls System.Attribute.GetCustomAttributes(ParameterInfo element)
    public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element)
    {
    return Attribute.GetCustomAttributes(element);
  4. Which finally calls the problematic API which does not handle the custom attribute provider correctly System.Reflection.CustomAttribute.GetCustomAttributes(ICustomAttributeProvider obj, Boolean inherit) in:
    public static Attribute[] GetCustomAttributes(ParameterInfo element) => (Attribute[])CustomAttribute.GetCustomAttributes(element, true);

    NOTE: inherit parameter defaults to true in this path.

With the provided workaround we would intercept the step 2) and instead directly call the locally defined override https://github.com/dotnet/aspnetcore/blob/402e7fc10aa304775f50d318c8a4dafbf46dbfe0/src/Shared/PropertyAsParameterInfo.cs#L158
whose implementation invokes GetCustomAttributes on the base types (which work correctly).


@tmds @janani66 Would this be a viable workaround for you?

@tmds
Copy link
Member

tmds commented Dec 14, 2023

@ivanpovazan do you know if the test failures indicate product bugs?

The backport request is closed assuming it will only address test failures and not actual product bugs.

If we can demonstrate these are relevant product bugs, the decision to backport can be revisited.

@ivanpovazan
Copy link
Member

@ivanpovazan do you know if the test failures indicate product bugs?

They indicate that using a custom attribute provider like: internal sealed class PropertyAsParameterInfo : ParameterInfo and GetCustomAttributes API with Mono can cause runtime failures.

However, I am not sure how common such pattern is, as it would have been reported before.
Additionally, as far as I know, there weren't any dotnet/runtime unit tests covering such usage (tests were added with the fix), which indicates this bug existed for some time (for what its worth, the original issue is reproducible with .NET7 as well).

@github-actions github-actions bot locked and limited conversation to collaborators Jan 14, 2024
@akoeplinger akoeplinger removed this from the 8.0.x milestone Jan 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM Servicing-rejected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants