Repository navigation
Description
Description
Aspnet service crashes on SIGSEGV when compiled for linux-arm64 and targeted to net9.0.
It does not crash on windows at all, also as on windows and linux when targeted to net8.0.
Reproduction Steps
Unfortunately I have no repro steps (other than just run the service and send few http requests to it).
On Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-125-generic aarch64) it looks like it just randomly crashes.
Installed dotnet: 9.0.101.
Expected behavior
Don't crash even on linux-arm64, please 😁
Actual behavior
There is a crash report available which - when preprocessed by apport-unpack /var/crash/_usr_lib_dotnet_dotnet.1000.crash ~/crash - can provide a dump. As there is possibly sensitive data in the dump, I can share it for inspection only via some "more secure" channels, if needed. I'm far from being expert here, but I'm able to open it in WinDbg and observe following:
(12f144.12f14a): Signal SIGSEGV (Segmentation fault) code SEGV_MAPERR (Address not mapped to object) at 0xffbe9093ca2a
*** WARNING: Unable to verify timestamp for libcoreclr.so
libcoreclr!alloc_context::init_alloc_count [inlined in libcoreclr!SVR::GCHeap::FixAllocContext+0x14]:
0000ffff`850eca54 79406428 ldrh w8,[x1,#0x32]
Under the "Stack" section, there is:
[0x0] libcoreclr!alloc_context::init_alloc_count (Inline Function) (Inline Function)
[0x1] libcoreclr!SVR::GCHeap::FixAllocContext+0x14 0xffff44246540 0xffff84fd94f8
[0x2] libcoreclr!GCToEEInterface::GcEnumAllocContexts+0x54 0xffff44246570 0xffff850a6210
[0x3] libcoreclr!SVR::gc_heap::fix_allocation_contexts+0x28 (Inline Function) (Inline Function)
[0x4] libcoreclr!SVR::gc_heap::garbage_collect+0x60 0xffff442465a0 0xffff850a3f44
[0x5] libcoreclr!SVR::gc_heap::gc_thread_function+0xca8 0xffff44246670 0xffff850a329c
[0x6] libcoreclr!SVR::gc_heap::gc_thread_stub+0x38 0xffff442466f0 0xffff84fdc420
[0x7] libcoreclr!<unnamed-namespace>::CreateNonSuspendableThread::$_0::operator()+0x3c (Inline Function) (Inline Function)
[0x8] libcoreclr!<unnamed-namespace>::CreateNonSuspendableThread::$_0::__invoke+0x50 0xffff44246710 0xffff852cafb0
[0x9] libcoreclr!CorUnix::CPalThread::ThreadEntry+0x1b8 0xffff44246740 0xffff8556d5c8
[0xa] libc_so+0x7d5c8 0xffff44246800 0x0
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Activity
mangod9 commentedon Dec 5, 2024
Thanks for reporting the issue. Does it repro frequently? Please share a dump (multiple if available) via email if possible.
pavel-faltynek commentedon Dec 5, 2024
Yes, it fails periodically (but have no clue, what is the exact trigger). We have
systemdmanaged restarts also as load balancer checking the service health over http requests (so it's kind of active immediately after startup). Firstly I was thinking the first "non-health" (bigger) request crashes it, but this might not be the case.I will (try to) send you the dumps over mail.
(Mail attachment failed, sent via alternative method).
pavel-faltynek commentedon Dec 6, 2024
I have tried the trivial
dotnet new webapi,dotnet new webapiaotdirectly on the target system (curling over http/https), additionally adding explicit request to invokeGC.Collect(), but no issue here at all. All was compiled/published on the target system, which leads me to a question:Might the behavior somehow depend (even non-intentionally) on the platform the application is built on? (we build/publish on windows machines and then deploy the result to linux servers):
dotnet publish $project --configuration $configuration --framework $framework --runtime $runtime --no-self-contained --output $outputFor the reported case,
$framework = 'net9.0',$runtime = 'linux-arm64'.mangod9 commentedon Dec 6, 2024
Thanks for sharing the dump. It appears that Thread::GetAllocContext is returning an invalid context. In 9 this part of the code was touched in #103055 and #103607.
@jkoritzinsky, do you think any of those changes would cause a race on arm64?
@pavel-faltynek, would be helpful if you can share a few more dumps -- assume all of them AV with the same stack? And any other specific details and/or a repro would be helpful.
jkoritzinsky commentedon Dec 7, 2024
I know we had to do some fixes for during process shutdown (on Windows) in #103877.
My first guess would be that this is happening because the alloc context for a thread was destroyed, but the
Threadobject for the thread is still around, but the thread object cleans itself up in co-op mode, so it shouldn't be possible to race with the GC there.Maybe there's a corresponding shutdown issue for Linux?
I can't think of anything else without looking at the dump myself.
mangod9 commentedon Dec 7, 2024
In this particular case doesnt look like it's occurring during shutdown. I have shared the dump with you offline.
jkotas commentedon Dec 9, 2024
The crash dump shows that the runtime was not notified about thread shutting down. It is most likely an managed/native interop problem (e.g. bug in interop corrupting unmanaged heap). I can see from the crash dump that your service uses number of nuget packages - the interop bug might be in one of them.
It may be useful to run it on checked build CoreCLR to see whether it will give us any extra insights. Could you please give it a try?
Download https://dev.azure.com/dnceng-public/_apis/resources/Containers/44080360/Libraries_CheckedCoreCLR_BuildArtifacts_linux_arm64_Debug?itemPath=Libraries_CheckedCoreCLR_BuildArtifacts_linux_arm64_Debug%2FLibraries_CheckedCoreCLR_BuildArtifacts_linux_arm64_Debug.tar.gz (this is recent CoreCLR checked CI build from release/9.0 branch)
Copy
coreclr/linux.arm64.Checked/*from the downloaded archive over/usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.0(create backup of this directory first if it is not a throw-away installation)Run your service. Collect crash dumps or any assert messages.
pavel-faltynek commentedon Dec 9, 2024
@jkotas, it doesn't seem I can access this. I have tried to randomly accept "account and project creation" in
dev.azure.com(after login to my "live/microsoft" account), but these portals are over complicated to me (meaning I'm not patient enough to get oriented). Any chance you could just share it? Thank you.pavel-faltynek commentedon Dec 9, 2024
@mangod9, generating more dumps might be the easier part. As far as I can remember all of the ones I loaded in WinDbg had the same call stack.
I have added:
25 remaining items
pavel-faltynek commentedon Jan 3, 2025
I can confirm that not setting the crypto hooks seems to help. The service just happily runs and serves requests without crashes (will give it more time, but I guess it's explained).
janvorli commentedon Jan 3, 2025
These are the last entries in the stresslog (it needs to be from bottom to up, see the timestamps), confirming what @kouvel has already figured.
janvorli commentedon Jan 3, 2025
And the caller of the
JIT_ReversePInvokeEnterRarein the call stack dumped above wasMailClient.Push.Api.MemoryAllocationsTracker.CryptoFree(Void*)dotnet-policy-service commentedon Jan 9, 2025
Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.
kouvel commentedon Jan 28, 2025
Creating a new thread object after the previous one is destructed is not ideal either, as the new thread object may have a different managed thread ID, and C++
thread_localvariables are used in several places. I'm not sure it's worth fixing at the moment.@pavel-faltynek, it sounds like you were able to work around the problem. Can this issue be closed?
jkotas commentedon Jan 28, 2025
@kouvel Can we detect an attempt to re-initialize the runtime thread object and abort immediately to make this issue easier to diagnose next time?
kouvel commentedon Jan 29, 2025
I can look into that. Need to check, but we may need to store the already-destructed info in pthread thread-specific data, as there were some reports that there may be issues with using
thread_localvars on macOS after they have been destroyed.jkotas commentedon Jan 29, 2025
It is ok if the detection is not 100% reliable or crashing when the re-initialization is triggered. My main objective is to get a crash dump with the component that's triggering the re-initialization on the stack.
pavel-faltynek commentedon Feb 4, 2025
Yes. Thank you all for sorting it out.