Skip to content

aspnetcore tests having Dynamic.Proxy fails on ppc64le architecture #93770

Closed

Description

@Sapana-Khemkar

Description

Around 6000+ aspnetcore tests which are using Dynamic.Proxy are failing on ppc64le with mono complier.

Reproduction Steps

build aspnetcore on ppc64le using cross built net8 rc2 and run tests.

Expected behavior

All tests should pass

Actual behavior

We get below error for 6000+ tests

Microsoft.AspNetCore.Server.Kestrel.Core.Tests.ConnectionContextTests.ParameterlessAbortCreateConnectionAbortedException
System.InvalidCastException : Specified cast is not valid.
  at Castle.DynamicProxy.Internal.AttributeUtil.ReadAttributeValue(CustomAttributeTypedArgument argument)
  at Castle.DynamicProxy.Internal.AttributeUtil.GetArguments(IList`1 constructorArguments, Type[]& constructorArgTypes, Object[]& constructorArgs)
  at Castle.DynamicProxy.Internal.AttributeUtil.CreateInfo(CustomAttributeData attribute)
  at Castle.DynamicProxy.Internal.AttributeUtil.GetNonInheritableAttributes(MemberInfo member)+MoveNext()
  at System.Linq.Enumerable.SelectEnumerableIterator`2[[Castle.DynamicProxy.CustomAttributeInfo, Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc],[System.Reflection.Emit.CustomAttributeBuilder, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
  at Castle.DynamicProxy.Generators.MetaProperty.BuildPropertyEmitter(ClassEmitter classEmitter)
  at Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementProperty(ClassEmitter emitter, MetaProperty property, ProxyGenerationOptions options)
  at Castle.DynamicProxy.Contributors.CompositeTypeContributor.Generate(ClassEmitter class, ProxyGenerationOptions options)
  at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
  at Castle.DynamicProxy.Generators.ClassProxyGenerator.<>c__DisplayClass1_0.<GenerateCode>b__0(String n, INamingScope s)
  at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
  at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
  at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
  at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
  at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
  at Moq.CastleProxyFactory.CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, Object[] arguments)
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.ConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].InitializeInstancePexProtected()
  at Moq.PexProtector.Invoke(Action action)
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.ConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].InitializeInstance()
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.ConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnGetObject()
  at Moq.Mock.get_Object()
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.ConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].get_Object()
  at Microsoft.AspNetCore.Server.Kestrel.Core.Tests.ConnectionContextTests.ParameterlessAbortCreateConnectionAbortedException() in /_/src/Servers/Kestrel/Core/test/ConnectionContextTests.cs:line 21
  at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
  at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
0.0321365s✘ Microsoft.AspNetCore.Server.Kestrel.Core.Tests.ConnectionDispatcherTests.OnConnectionCreatesLogScopeWithConnectionId
System.InvalidCastException : Specified cast is not valid.
  at Castle.DynamicProxy.Internal.AttributeUtil.ReadAttributeValue(CustomAttributeTypedArgument argument)
  at Castle.DynamicProxy.Internal.AttributeUtil.GetArguments(IList`1 constructorArguments, Type[]& constructorArgTypes, Object[]& constructorArgs)
  at Castle.DynamicProxy.Internal.AttributeUtil.CreateInfo(CustomAttributeData attribute)
  at Castle.DynamicProxy.Internal.AttributeUtil.GetNonInheritableAttributes(MemberInfo member)+MoveNext()
  at System.Linq.Enumerable.SelectEnumerableIterator`2[[Castle.DynamicProxy.CustomAttributeInfo, Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc],[System.Reflection.Emit.CustomAttributeBuilder, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
  at Castle.DynamicProxy.Generators.MetaProperty.BuildPropertyEmitter(ClassEmitter classEmitter)
  at Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementProperty(ClassEmitter emitter, MetaProperty property, ProxyGenerationOptions options)
  at Castle.DynamicProxy.Contributors.CompositeTypeContributor.Generate(ClassEmitter class, ProxyGenerationOptions options)
  at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
  at Castle.DynamicProxy.Generators.ClassProxyGenerator.<>c__DisplayClass1_0.<GenerateCode>b__0(String n, INamingScope s)
  at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
  at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
  at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
  at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
  at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
  at Moq.CastleProxyFactory.CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, Object[] arguments)
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].InitializeInstancePexProtected()
  at Moq.PexProtector.Invoke(Action action)
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].InitializeInstance()
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnGetObject()
  at Moq.Mock.get_Object()
  at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].get_Object()
  at Microsoft.AspNetCore.Server.Kestrel.Core.Tests.ConnectionDispatcherTests.OnConnectionCreatesLogScopeWithConnectionId() in /_/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs:line 33
--- End of stack trace from previous location ---
Output:
| [0.007s] TestLifetime Information: Starting test OnConnectionCreatesLogScopeWithConnectionId at 2023-10-17T17:03:42
| [0.039s] Microsoft.AspNetCore.Server.Kestrel.Core.Tests.ConnectionDispatcherTests Error: Test threw an exception.
| System.InvalidCastException: Specified cast is not valid.
|    at Castle.DynamicProxy.Internal.AttributeUtil.ReadAttributeValue(CustomAttributeTypedArgument argument)
|    at Castle.DynamicProxy.Internal.AttributeUtil.GetArguments(IList`1 constructorArguments, Type[]& constructorArgTypes, Object[]& constructorArgs)
|    at Castle.DynamicProxy.Internal.AttributeUtil.CreateInfo(CustomAttributeData attribute)
|    at Castle.DynamicProxy.Internal.AttributeUtil.GetNonInheritableAttributes(MemberInfo member)+MoveNext()
|    at System.Linq.Enumerable.SelectEnumerableIterator`2[[Castle.DynamicProxy.CustomAttributeInfo, Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc],[System.Reflection.Emit.CustomAttributeBuilder, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
|    at Castle.DynamicProxy.Generators.MetaProperty.BuildPropertyEmitter(ClassEmitter classEmitter)
|    at Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementProperty(ClassEmitter emitter, MetaProperty property, ProxyGenerationOptions options)
|    at Castle.DynamicProxy.Contributors.CompositeTypeContributor.Generate(ClassEmitter class, ProxyGenerationOptions options)
|    at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
|    at Castle.DynamicProxy.Generators.ClassProxyGenerator.<>c__DisplayClass1_0.<GenerateCode>b__0(String n, INamingScope s)
|    at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
|    at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
|    at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
|    at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
|    at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
|    at Moq.CastleProxyFactory.CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, Object[] arguments)
|    at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].InitializeInstancePexProtected()
|    at Moq.PexProtector.Invoke(Action action)
|    at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].InitializeInstance()
|    at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnGetObject()
|    at Moq.Mock.get_Object()
|    at Moq.Mock`1[[Microsoft.AspNetCore.Connections.DefaultConnectionContext, Microsoft.AspNetCore.Connections.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].get_Object()
|    at Microsoft.AspNetCore.Server.Kestrel.Core.Tests.ConnectionDispatcherTests.OnConnectionCreatesLogScopeWithConnectionId() in /_/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs:line 33
|    at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_0.<<InvokeTestMethodAsync>b__1>d[[Xunit.Sdk.IXunitTestCase, xunit.core, Version=2.4.2.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c]].MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 264
| --- End of stack trace from previous location ---
|    at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
|    at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90
| [0.055s] TestLifetime Information: Finished test OnConnectionCreatesLogScopeWithConnectionId in 0.0478395s

Regression?

No response

Known Workarounds

No response

Configuration

.NET 8 RC1 cross built for the linux-ppc64 target (using the Mono runtime by default).

dotnet --info
.NET SDK:
 Version:   8.0.100-rc.2.23502.2
 Commit:    0abacfc2b6

Runtime Environment:
 OS Name:     rhel
 OS Version:  8
 OS Platform: Linux
 RID:         linux-ppc64le
 Base Path:   /root/ashutosh/aspnetcore-crossbuild/aspnetcore/.dotnet/sdk/8.0.100-rc.2.23502.2/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-rc.2.23479.6
  Architecture: ppc64le
  Commit:       0b25e38ad3

.NET SDKs installed:
  8.0.100-rc.2.23502.2 [/root/ashutosh/aspnetcore-crossbuild/aspnetcore/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0-ci [/root/ashutosh/aspnetcore-crossbuild/aspnetcore/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [/root/ashutosh/aspnetcore-crossbuild/aspnetcore/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [/root/ashutosh/aspnetcore-crossbuild/aspnetcore/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Other information

No response

cc: @janani66 @tmds @uweigand

Activity

  1. ghost added
    untriaged
    on Oct 20, 2023
  2. ghost added
    needs-area-label
    on Oct 20, 2023
  3. jeffschwMSFT commented on Oct 20, 2023

    @jeffschwMSFT
    Member

    Given the stack trace, I think you should follow-up with the owner of (https://www.nuget.org/packages/Castle.DynamicProxy). Given the context, this is possibly an Endianness issue.

  4. jeffschwMSFT commented on Oct 23, 2023

    @jeffschwMSFT
    Member

    closing, please follow-up with Castle to take a look

  5. ghost removed
    untriaged
    on Oct 23, 2023
  6. tmds commented on Oct 24, 2023

    @tmds
    Member

    Given the context, this is possibly an Endianness issue.

    I don't think this is an endianness issue. pple64 is little-endian, like x64.

    I ran the aspnetcore tests on x64 with a mono runtime, and they show the same issue.

  7. ghost added
    untriaged
    on Oct 24, 2023
  8. added and removed
    untriaged
    on Oct 24, 2023
  9. Sapana-Khemkar commented on Oct 25, 2023

    @Sapana-Khemkar
    ContributorAuthor

    @tmds @jeffschwMSFT these tests were passing till .NET8 Preview6. From Preview7 we are observing these failures. So something changed in runtime between preview6 and preview7 which is causing this issue.
    Also note from every time when httpConnection trying to access Mock object issue is reproduced. If you have any inputs based on previous experience do share

  10. tmds commented on Oct 25, 2023

    @tmds
    Member

    @lambdageek @akoeplinger may be you have some thoughts on what changes went in since preview 6 that might cause cause this to start failing?

  11. lambdageek commented on Oct 25, 2023

    @lambdageek
    Member

    @tmds Maybe #87406 /cc @ivanpovazan

    (I'm looking through v8.0.0-preview.6.23329.7...v8.0.0-preview.7.23375.6 )

    @tmds you said you can repro the failure on x64? Could you share the repro steps

  12. ivanpovazan commented on Oct 25, 2023

    @ivanpovazan
    Member

    @tmds Maybe #87406 /cc @ivanpovazan

    I can take a look. Repro steps would be much appreciated.

  13. 19 remaining items

  14. lambdageek commented on Oct 31, 2023

    @lambdageek
    Member

    There is something strange going on with the vtable for Microsoft.EntityFrameworkCore.Metadata.Internal.Property. if I build EFCore from source and debug it under mono, the call from public static ValueGenerated? GetValueGenerated(IReadOnlyProperty property) to property.GetContainingForeignKeys() ends up in Property.IsIndex. This is the immediately following method declared in IReadOnlyProperty after GetContainingForeignKeys, so it looks like the vtable slots are populated incorrectly.

    I also tried adding a call to property.GetContainingIndexes and it ends up in IReadOnlyProperty.IsPrimaryKey.

    So there is an off by one somewhere.

    I guess I'll look at the vtable setup trace in more detail again.

  15. lambdageek commented on Nov 3, 2023

    @lambdageek
    Member

    I got a little bit further with this yesterday, but had to context switch to something else.

    The problem is somewhere between mono's IMT (interface method table) builder and the generated IMT trampoline: The virtcall to IReadOnlyProperty:GetContainingForeignKeys goes through an IMT trampoline that turns an interface method call into a vtable call through the actual implementation object. The IMT builder is responsible for populating the IMT slots of a concrete class with a purpose-built dispatcher method (that depends on the actual interfaces implemented by a particular class). And the dispatcher method ends up invoking a method at some particular offset in the vtable of that concrete class.

    What I've observed (via some printfs and some lldb debugging) is that the dispatcher ends up with the offset of IsIndex instead of GetContainingForeignKeys.

    I ran out of time yesterday to see if:

    1. the vtable is messed up from the outset, or
    2. the builder is inserting an incorrect offset into the dispatcher method right from the outset, or
    3. the initial builder is constructed correctly, but becomes corrupted by the time the dispatcher method is generated, or
    4. the dispatcher algorithm is broken (it's meant to do some kind of a binary search among all the vtable methods that are assigned to a particular IMT slot that ended up colliding).

    Update incidentally this is why trying to recreate this scenario with a smaller sample mimicing the EFCore class hierarchy is challenging - the IMT slots are populated based on hashing of namespaces/class names/method names/return and arguent type names. Creating the same exact hash collisions is hard.

  16. lambdageek commented on Nov 6, 2023

    @lambdageek
    Member

    It's a problem in the IMT builder. When build_imt_slots iterates over all the methods of a particular interface, it manually keeps track of the current vt_slot for the methods of that interface starting from interface_offset. The logic for incrementing vt_slot was incorrect: if there is a generic non-virtual method in the interface, the vt_slot was incremented when it should not have been. As a result the IMT builder added an incorrect implementing method for the IMT slot.

    has_generic_virtual = TRUE;
    vt_slot ++;

    these two lines need to be under an if (m_method_is_virtual (method))

    PR shortly.

    I want to think a little bit harder whether we can make a test case - I'm not sure if we really depend on an IMT slot collision to exhibit the problem or if it will show up if I can make it show up even with a single method per IMT slot

  17. ghost added
    in-pr
    on Nov 6, 2023
  18. ghost removed
    in-pr
    on Nov 8, 2023
  19. lambdageek commented on Nov 13, 2023

    @lambdageek
    Member

    The backports for .NET 6, 7, 8 have been merged.

  20. locked and limited conversation to collaborators on Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions