runtime: Access Violation Exception after upgrading from .NET 8 to .NET 9

Description

We recently upgraded from .NET 8 to .NET 9 and start to experience crashes in our tests

Faulting application name: testhost.exe, version: 17.1200.24.56501, time stamp: 0x63740000
Faulting module name: coreclr.dll, version: 9.0.24.52809, time stamp: 0x672049fc
Exception code: 0xc0000005
Fault offset: 0x00000000002eea8b
Faulting process id: 0x2c8c
Faulting application start time: 0x01db4ea81cad46d8
Faulting application path: c:\Jenkins\workspace\Testsv70_Winx64\s\test\SlowTests\bin\Release\net9.0\testhost.exe
Faulting module path: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.0\coreclr.dll
Report Id: 3804b1ee-81a8-4f06-bef5-760530d90989
Faulting package full name: 
Faulting package-relative application ID: 
Application: testhost.exe
CoreCLR Version: 9.0.24.52809
.NET Version: 9.0.0
Description: The process was terminated due to an unhandled exception.
Stack:
   at System.Runtime.ExceptionServices.InternalCalls.RhpCallFinallyFunclet(Byte*, Void*, ExInfo*)
   at System.Runtime.ExceptionServices.InternalCalls.RhpCallFinallyFunclet(Byte*, Void*, ExInfo*)
   at System.Runtime.EH.InvokeSecondPass(ExInfo ByRef, UInt32, UInt32)
   at System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef)
   at System.Runtime.EH.RhRethrow(ExInfo ByRef, ExInfo ByRef)
   at Raven.Server.Documents.Replication.Incoming.AbstractIncomingReplicationHandler`2[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, 
Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, 
PublicKeyToken=7cec85d7bea7798e]].ReceiveReplicationBatches()
   at Raven.Server.Documents.Replication.Incoming.AbstractIncomingReplicationHandler`2[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, 
Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, 
PublicKeyToken=7cec85d7bea7798e]].DoIncomingReplication()
   at Raven.Server.Utils.PoolOfThreads+PooledThread.DoWork()
   at Raven.Server.Utils.PoolOfThreads+PooledThread.Run()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

Will attach the dump privately. https://developercommunity.visualstudio.com/t/Access-Violation-Exception-after-upgradi/10814326

Reproduction Steps

Not at the moment.

Expected behavior

not to crash with an AVE

Actual behavior

crashing with an AVE

Regression?

Yes, this was working without crashing on .NET 8

Known Workarounds

No response

Configuration

No response

Other information

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 28 (15 by maintainers)

Most upvoted comments

@karmeli87 it might be related to the EH changes, as the GC stack walk needs to do some special things when exception handling is in progress. Would it be possible for you to try to run with the new EH disabled to see if it gets rid of the crash? You can do it either by setting the env variable DOTNET_LegacyExceptionHandling=1 or by setting System.Runtime.LegacyExceptionHandling to true in the runtimeconfig.json file.

@karmeli87 I’ve investigated the dump and there is clearly a GC hole somewhere. The stress log dump worked fine for me and helped me to reveal some details. There are two objects that the last GC run has logged as having invalid MethodTable and I’ve found that their references are pointing to the GC heap, but into the middle of another object. So at some point, GC must have scanned the stack and not get their roots reported, then moved objects on the heap and thus these references are pointing wrong places. Trying to find the real reason for the GC heap is like searching for a needle in a haystack, so it will take me some time. The method in which these two references are stored on the stack is the Raven.Server.Documents.Replication.Incoming.AbstractIncomingReplicationHandler`2[[System.__Canon, System.Private.CoreLib],[System.__Canon, System.Private.CoreLib]].ReceiveReplicationBatches() It is huge (almost 8kB) and contains 47 exception handling records (11 original clauses and the rest are cloned and duplicate ones generated by JIT due to specific EH reasons). That makes the investigation even more fun.

@karmeli87 It would be great to get linux dumps as well. Chances are it is the same issue.