Skip to content

Assert failure(PID 2292 [0x000008f4], Thread: 2312 [0x0908]): !g_pConfig->fAssertOnFailFast() || (m_Next == FRAME_TOP) || (*m_Next->GetGSCookiePtr() == GetProcessGSCookie()) #33613

Closed

Description

@AriNuer

Job:
runtime-coreclr gcstress0x3-gcstress0xc:20200315.1
Error message:

Assert failure(PID 2292 [0x000008f4], Thread: 2312 [0x0908]): !g_pConfig->fAssertOnFailFast() || (m_Next == FRAME_TOP) || (*m_Next->GetGSCookiePtr() == GetProcessGSCookie())

CORECLR! Frame::Push + 0x1A9 (0x00007ff956303ad9)
CORECLR! Frame::Push + 0xDE (0x00007ff956303c0a)
CORECLR! Thread::RedirectedHandledJITCase + 0x1AD (0x00007ff9561b7a05)
CORECLR! RedirectedHandledJITCaseForGCStress_Stub + 0x26 (0x00007ff956615a06)
<no module>! <no symbol> + 0x0 (0x00007ff8f72c00f5)
<no module>! <no symbol> + 0x0 (0x00007ff8f6e0f518)
<no module>! <no symbol> + 0x0 (0x0000000000003039)
<no module>! <no symbol> + 0x0 (0x000000000000018c)
<no module>! <no symbol> + 0x0 (0xffffffffffffffff)
<no module>! <no symbol> + 0x0 (0x9abcdef012345678)
File: F:\workspace\_work\1\s\src\coreclr\src\vm\frames.cpp Line: 417
Image: C:\h\w\B366092E\p\CoreRun.exe

Return code: 1\r\nRaw output file: C:\h\w\B366092E\w\AA26098B\e\Interop\NativeCallable\Reports\Interop.NativeCallable\NativeCallableTest\NativeCallableTest.output.txt
Raw output:
BEGIN EXECUTION
"C:\h\w\B366092E\p\corerun.exe" NativeCallableTest.dll
Running TestNativeCallableValid...
Running TestNativeCallableValid_OnNewNativeThread...
Running TestNativeCallableValid_PrepareMethod...
Running NegativeTest_NonStaticMethod...
Running NegativeTest_ViaDelegate...
Running NegativeTest_NonBlittable...
Running NegativeTest_NonInstantiatedGenericArguments...
Running NegativeTest_InstantiatedGenericArguments...
Running NegativeTest_FromInstantiatedGenericClass...
Running TestNativeCallableViaUnmanagedCalli...
Running TestNativeCallableValid_ThrowException...
Expected: 100
Actual: -1073740286
END EXECUTION - FAILED
FAILED
Test Harness Exitcode is : 1
To run the test:
> set CORE_ROOT=C:\h\w\B366092E\p
> C:\h\w\B366092E\w\AA26098B\e\Interop\NativeCallable\NativeCallableTest\NativeCallableTest.cmd
Expected: True
Actual: False

Stack trace:
at Interop_NativeCallable._NativeCallableTest_NativeCallableTest_._NativeCallableTest_NativeCallableTest_cmd() in F:\workspace\_work\1\s\artifacts\tests\coreclr\Windows_NT.x64.Checked\TestWrappers\Interop.NativeCallable\Interop.NativeCallable.XUnitWrapper.cs:line 140
Details:
https://dev.azure.com/dnceng/public/_build/results?buildId=560162&view=ms.vss-test-web.build-test-results-tab&runId=17645012&resultId=101118&paneView=debug

Activity

  1. added
    untriaged
    on Mar 16, 2020
  2. added and removed
    untriaged
    on Mar 16, 2020
  3. added this to the 5.0 milestone on Mar 16, 2020
  4. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    @jkotas or @janvorli Any suggestions here on how to address this for Windows would be helpful. I have a fix for #33612, but this one seems related to the exception handling side of things that I am less knowledgable about how to mitigate.

  5. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    This is easy to reproduce locally. Looks like an issue with TestNativeCallableValid_ThrowException() test.

    private const int CallbackThrowsErrorCode = 27;
    [NativeCallable]
    public static int CallbackThrows(int val)
    {
    throw new Exception() { HResult = CallbackThrowsErrorCode };
    }
    public static void TestNativeCallableValid_ThrowException()
    {
    Console.WriteLine($"Running {nameof(TestNativeCallableValid_ThrowException)}...");
    /*
    void NativeCallableValid_ThrowException()
    {
    .locals init ([0] native int ptr)
    IL_0000: nop
    IL_0001: ldftn int32 CallbackThrows(int32)
    IL_0007: stloc.0
    IL_0008: ldloc.0
    IL_0009: ldc.i4 <n> local
    IL_000e: call bool NativeCallableDll::CallManagedProcCatchException(native int, int)
    IL_0013: ret
    }
    */
    DynamicMethod testNativeCallable = new DynamicMethod("NativeCallableValid_ThrowException", typeof(int), null, typeof(Program).Module);
    ILGenerator il = testNativeCallable.GetILGenerator();
    il.DeclareLocal(typeof(IntPtr));
    il.Emit(OpCodes.Nop);
    // Get native function pointer of the callback
    il.Emit(OpCodes.Ldftn, typeof(Program).GetMethod(nameof(CallbackThrows)));
    il.Emit(OpCodes.Stloc_0);
    il.Emit(OpCodes.Ldloc_0);
    int n = 12345;
    il.Emit(OpCodes.Ldc_I4, n);
    il.Emit(OpCodes.Call, typeof(NativeCallableDll).GetMethod("CallManagedProcCatchException"));
    il.Emit(OpCodes.Ret);
    var testNativeMethod = (IntNativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(IntNativeMethodInvoker));
    // Method should have thrown and caught an exception.
    Assert.AreEqual(-1, testNativeMethod());
    }

  6. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    Bah. I think this is my bad. @jkotas If I recall a conversation about exceptions and the NativeCallableAttribute, the expectation here is that they don't mix at all and we shouldn't even be trying to validate them right? If so I will disable those tests since I added them just to have a set of scenarios I could validate fail. Looks like on GCStress they really don't work due to the stack walking logic in

    bool ExceptionTracker::HasFrameBeenUnwoundByAnyActiveException(CrawlFrame * pCF)

  7. jkotas commented on Mar 16, 2020

    @jkotas
    Member

    On Windows, the managed exception should get converted to SEH exception on the NativeCallable boundary.
    On Unix, the managed exception should become unhanded on the NativeCallable boundary.

  8. jkotas commented on Mar 16, 2020

    @jkotas
    Member

    I think we are missing "unwind and continue" on the NativeCallable boundary. @janvorli Do you have thoughts about the best way to fix that?

  9. 15 remaining items

  10. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    And even stranger, how come Aaron's fix doesn't help, as the OnGcCoverageInterrupt with his fix is checking for NULL Thread and if it is the case, it should just silently remove the hlt and go without ever going into the ProcessCLRException. I'm stepping through the code to see if I can find a clue.

    @janvorli That is because this is the PrepareMethod() scenario where the function is JITed from a thread that is initialized and only called on a thread that is external.

  11. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    @janvorli But you just pointed out to me how I think we can fix this.

  12. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    @janvorli Nope. I misunderstood why this was happening. Looks like the COOP transition is happening before the call to IsGcMarker() which would handle the case I fixed.

        {
            GCX_COOP();
            // Update the current establisher frame
            if (dwExceptionFlags & EXCEPTION_UNWINDING)
            {
                ExceptionTracker *pCurrentTracker = pThread->GetExceptionState()->GetCurrentExceptionTracker();
                if (pCurrentTracker != NULL)
                {
                    pCurrentTracker->SetCurrentEstablisherFrame(sf);
                }
            }
    
    #ifdef _DEBUG
            Thread::ObjectRefFlush(pThread);
    #endif // _DEBUG
        }
    
    
        //
        // begin Early Processing
        //
        {
    #ifndef USE_REDIRECT_FOR_GCSTRESS
            if (IsGcMarker(pContextRecord, pExceptionRecord))
            {
                returnDisposition = ExceptionContinueExecution;
                goto lExit;
            }
    #endif // !USE_REDIRECT_FOR_GCSTRESS
  13. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    Can we just create the Thread when we are doing GC stress and hit the GC stress exception handler?

    @jkotas Can you elaborate on this? @AndyAyersMS suggested I could update bool emitter::emitNoGChelper(CorInfoHelpFunc helpFunc) to have the Enter/Exit - the CORINFO_HELP_INIT_PINVOKE_FRAME is already present. Is that what you mean here?

  14. janvorli commented on Mar 16, 2020

    @janvorli
    Member

    It seems that the call to ProcessCLRException stems from something else than the GC coverage interrupt. I can see that the CLRVectoredExceptionHandlerShim correctly detects that the Thread is null and just removes the instrumentation and returns. And then a bit later, without any other CLRVectoredExceptionHandlerShim call, the ProcessCLRException is called and crash due to the Thread being NULL. There are hundreds of CLRVectoredExceptionHandlerShim calls to handle previous GC coverage interrupts before that and none of them results in a call to ProcessCLRException. So there is something happening that causes the call to occur (with error code 0xc0000096, which represents the coverage privileged instruction). I wonder if the CLRVectoredExceptionHandlerShim returns wrong return value or something like that. I keep looking...

  15. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    Yep the call to CLRVectoredExceptionHandlerShim() is returning EXCEPTION_CONTINUE_SEARCH during that hlt for GC cover. What should it be returning?

  16. janvorli commented on Mar 16, 2020

    @janvorli
    Member

    I think I've found the culprit - testing now ...

  17. janvorli commented on Mar 16, 2020

    @janvorli
    Member

    Yes, I was right. The problem is that the fix @AaronRobinsonMSFT did in OnGcCoverageInterrupt in #33615 was insufficient. We also need to make sure that the CLRVectoredExceptionHandlerShim returns EXCEPTION_CONTINUE_EXECUTION when bIsGCMarker is true and pThread is NULL. We were currently returning EXCEPTION_CONTINUE_SEARCH, which resulted in the incorrect call to ProcessCLRException.

  18. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    @janvorli I just tested that very scenario. My plan was to update if (pThread || fExceptionInEE) to if (pThread || fExceptionInEE || bIsGCMarker) in excep.cpp@7982?

  19. janvorli commented on Mar 16, 2020

    @janvorli
    Member

    I would put the following at line 7967. That is sufficient. I believe we don't need anything from the body of the if you've mentioned.

    else if (bIsGCMarker)
    {
        result = EXCEPTION_CONTINUE_EXECUTION;
    }
  20. janvorli commented on Mar 16, 2020

    @janvorli
    Member

    I also have a fix for the other issue, I will create a PR soon.

  21. AaronRobinsonMSFT commented on Mar 16, 2020

    @AaronRobinsonMSFT
    Member

    I will fold the above into the previous PR so it is complete.

  22. AaronRobinsonMSFT commented on Mar 17, 2020

    @AaronRobinsonMSFT
    Member

    Fixed with #33653 and #33615

  23. ghost locked as resolved and limited conversation to collaborators on Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions