Skip to content

Assert "rank < MAX_RANK" in runtime/src/coreclr/classlibnative/bcltype/arraynative.cpp Line: 812 #91349

Closed

Description

@amanasifkhalid

While testing Orleans with a Checked build of the .NET 8 Preview 7 runtime, I hit the following assert while running Orleans.Serialization.UnitTests on Linux x64: Assert "rank < MAX_RANK" in runtime/src/coreclr/classlibnative/bcltype/arraynative.cpp Line: 812. To reproduce:

  • Replace your .NET 8 Preview 7 installation's runtime with a Checked build
  • Upgrade Orleans to target .NET 8 (using the .NET upgrade-assistant tool, for example)
    • Orleans uses some obsolete APIs, so in order to build successfully, you'll have to ignore some Roslyn errors (SYSLIB0050, SYSLIB0051, CS0672)
  • Set DOTNET_JitRandomEdgeCounts=1
  • Run dotnet test -c Release

For reference, I reproduced this running Ubuntu-22.04 in WSL2.

cc @JulieLeeMSFT @ReubenBond

Activity

  1. ghost added
    needs-area-label
    on Aug 30, 2023
  2. ghost added
    untriaged
    on Aug 30, 2023
  3. adityamandaleeka commented on Aug 30, 2023

    @adityamandaleeka
    Member

    cc @AndyAyersMS since this involves the edge count randomization

  4. added
    area-CodeGen-coreclr
    and removed
    untriaged
    needs-area-label
    on Aug 30, 2023
  5. adityamandaleeka commented on Aug 30, 2023

    @adityamandaleeka
    Member

    Oh hey @amanasifkhalid, didn't notice that you were the one who filed this 😄

  6. added this to the 8.0.0 milestone on Aug 31, 2023
  7. AndyAyersMS commented on Sep 5, 2023

    @AndyAyersMS
    Member

    @amanasifkhalid did you upgrade all the orleans projects, or just some subset?

  8. AndyAyersMS commented on Sep 5, 2023

    @AndyAyersMS
    Member

    Also did you try a clean dotnet test with the checked jit or did you first try it with the normal jit and then retry (with presumably already built assets) with the checked jit?

    I'm asking because when I try installing the checked jit first CSC is failing with exit code 134. Perhaps my jit doesn't match, will look into this too.

  9. AndyAyersMS commented on Sep 5, 2023

    @AndyAyersMS
    Member

    If you have your changes still, can you put them on a branch of a fork of orleans that I can pull down, or else package them up as a patch?

  10. amanasifkhalid commented on Sep 5, 2023

    @amanasifkhalid
    ContributorAuthor

    @AndyAyersMS I upgraded all projects to .NET 8, and only used the Checked JIT to build and run tests, so I started from a clean slate. I didn't hit the CSC error... For consistency, I copied over libclrjit.so, libcoreclr.so, and System.Private.CoreLib.dll from my Checked build to my Preview 7 install.

    I've pushed my repro setup here -- setting DOTNET_JitRandomEdgeCounts=1 and running dotnet test -c Release should work out of the box (except for a few Roslyn errors thrown in unrelated tests). Please let me know if it doesn't reproduce. Thanks!

  11. amanasifkhalid commented on Sep 5, 2023

    @amanasifkhalid
    ContributorAuthor

    Also sorry for the red herring, but I tried reproducing this again, and I can hit the assert without DOTNET_JitRandomEdgeCounts or any other JIT env vars set.

  12. AndyAyersMS commented on Sep 5, 2023

    @AndyAyersMS
    Member

    Since the assert comes from the runtime it's likely it will repro with just a checked runtime/SPC and a release JIT. Anyways, let me get a repro and I'll dig into why this happens.

  13. AndyAyersMS commented on Sep 5, 2023

    @AndyAyersMS
    Member

    Ok, I can repro:

    cd test/Orleans.Serialization.UnitTests
    dotnet test -c Release --blame-crash 
    
    [createdump] Gathering state for process 28033 dotnet
    [createdump] Crashing thread 6db4 signal 6 (0006)
    [createdump] Writing full dump to file /tmp/47ee0b84-c35e-4220-968e-54b98196f229/dotnet_28033_1693953262_crashdump.dmp
    [createdump] Written 2773696512 bytes (677172 pages) to core file
    [createdump] Target process is alive
    [createdump] Dump successfully written in 4705ms
    
    The active test run was aborted. Reason: Test host process crashed : Assert failure(PID 28033 [0x00006d81], Thread: 28084 [0x6db4]): rank < MAX_RANK
        File: /home/andy/repos/runtime0/src/coreclr/classlibnative/bcltype/arraynative.cpp Line: 812
        Image: /usr/share/dotnet/dotnet
    waitpid() returned successfully (wstatus 00000000) WEXITSTATUS 0 WTERMSIG 0
    
  14. AndyAyersMS commented on Sep 5, 2023

    @AndyAyersMS
    Member

    Stack trace:

      * frame #0: 0x00007f8271110c7f libc.so.6`wait4 + 95
        frame #1: 0x00007f8270e834ce libcoreclr.so`PROCCreateCrashDump(argv=<unavailable>, errorMessageBuffer=0x0000000000000000, cbErrorMessageBuffer=0) at process.cpp:2278:22
        frame #2: 0x00007f8270e84924 libcoreclr.so`::PROCCreateCrashDumpIfEnabled(signal=<unavailable>, siginfo=<unavailable>) at process.cpp:2492:9
        frame #3: 0x00007f8270e80e78 libcoreclr.so`::PROCAbort(signal=6, siginfo=0x0000000000000000) at process.cpp:2521:5
        frame #4: 0x00007f8270e80d7e libcoreclr.so`::RaiseFailFastException(pExceptionRecord=<unavailable>, pContextRecord=<unavailable>, dwFlags=<unavailable>) at process.cpp:1267:5
        frame #5: 0x00007f8270c8414e libcoreclr.so`FailFastOnAssert() at debug.cpp:60:5
        frame #6: 0x00007f8270c83e88 libcoreclr.so`::_DbgBreakCheck(szFile="/home/andy/repos/runtime0/src/coreclr/classlibnative/bcltype/arraynative.cpp", iLine=812, szExpr="rank < MAX_RANK", fConstrained=<unavailable>) at debug.cpp:288:5
        frame #7: 0x00007f8270c841da libcoreclr.so`_DbgBreakCheckNoThrow(szFile="/home/andy/repos/runtime0/src/coreclr/classlibnative/bcltype/arraynative.cpp", iLine=812, szExpr="rank < MAX_RANK", fConstrained=NO) at debug.cpp:307:18
        frame #8: 0x00007f8270c84523 libcoreclr.so`::DbgAssertDialog(szFile="/home/andy/repos/runtime0/src/coreclr/classlibnative/bcltype/arraynative.cpp", iLine=812, szExpr=<unavailable>) at debug.cpp:0
        frame #9: 0x00007f8270d7748f libcoreclr.so`ArrayNative::CreateInstance(pElementTypeUNSAFE=<unavailable>, rank=32, pLengths=0x00007f4277b55210, pLowerBounds=0x0000000000000000) at arraynative.cpp:812:9
    
    00007F40EEFF9370 00007f8271110c7f [HelperMethodFrame_PROTECTOBJ: 00007f40eeff9370] System.Array.InternalCreate(System.RuntimeType, Int32, Int32*, Int32*)
    00007F40EEFF94B0 00007F81F1719FEA System.Array.CreateInstance(System.Type, Int32[])
    00007F40EEFF94E0 00007F820120D3CD Orleans.Serialization.Codecs.MultiDimensionalArrayCodec`1[[System.Int32, System.Private.CoreLib]].ReadValue[[Orleans.Serialization.Buffers.ReadOnlySequenceInput, Orleans.Serialization]](Orleans.Serialization.Buffers.Reader`1<Orleans.Serialization.Buffers.ReadOnlySequenceInput> ByRef, Orleans.Serialization.WireProtocol.Field) [/home/andy/repos/orleans/src/Orleans.Serialization/Codecs/MultiDimensionalArrayCodec.cs @ 120]
    00007F40EEFF95E0 00007F820070CF77 Orleans.Serialization.Codecs.UntypedCodecWrapper`1[[System.__Canon, System.Private.CoreLib]].ReadValue[[Orleans.Serialization.Buffers.ReadOnlySequenceInput, Orleans.Serialization]](Orleans.Serialization.Buffers.Reader`1<Orleans.Serialization.Buffers.ReadOnlySequenceInput> ByRef, Orleans.Serialization.WireProtocol.Field)
    00007F40EEFF9640 00007F820120CFA9 OrleansCodeGen.Orleans.Serialization.UnitTests.Codec_ArrayPoco`1[[System.Int32, System.Private.CoreLib]].Deserialize[[Orleans.Serialization.Buffers.ReadOnlySequenceInput, Orleans.Serialization]](Orleans.Serialization.Buffers.Reader`1<Orleans.Serialization.Buffers.ReadOnlySequenceInput> ByRef, Orleans.Serialization.UnitTests.ArrayPoco`1<Int32>) [/home/andy/repos/orleans/test/Orleans.Serialization.UnitTests/Orleans.CodeGenerator/Orleans.CodeGenerator.OrleansSerializationSourceGenerator/Orleans.Serialization.UnitTests.orleans.g.cs @ 3358]
    

    Assert is

    _ASSERTE(rank < MAX_RANK); // Ensures that the stack buffer size allocations below won't overlow

    with

    #define MAX_RANK 32

    and the code is requesting a rank-32 array:

    (lldb) dumparray 00007f4277b55200
    Name:        System.Int32[]
    MethodTable: 00007f81f29f6630
    EEClass:     00007f81f29f6580
    Size:        152(0x98) bytes
    Array:       Rank 1, Number of elements 32, Type Int32
    

    elsewhere we see 32 should be ok:

                if (rank > MAX_RANK)
                {
                    ThrowTypeLoadException(pKey, IDS_CLASSLOAD_RANK_TOOLARGE);
                }

    so the assert in arraynative.cpp is too aggressive, and should be

    _ASSERTE(rank <= MAX_RANK); // Ensures that the stack buffer size allocations below won't overflow
  15. added a commit that references this issue on Sep 5, 2023
    d260b28
  16. ghost added
    in-pr
    on Sep 5, 2023
  17. added a commit that references this issue on Sep 6, 2023
    808c523
  18. ghost removed
    in-pr
    on Sep 6, 2023
  19. ghost locked as resolved and limited conversation to collaborators on Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions