Skip to content

ASPNet service crashing on linux-arm64 when targeted to net9.0 #110442

Closed

Description

@pavel-faltynek

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

  1. ghost added
    needs-area-label
    on Dec 5, 2024
  2. added and removed
    needs-area-label
    on Dec 5, 2024
  3. added
    untriaged
    on Dec 5, 2024
  4. removed
    untriaged
    on Dec 5, 2024
  5. added this to the 10.0.0 milestone on Dec 5, 2024
  6. mangod9 commented on Dec 5, 2024

    @mangod9
    Member

    Thanks for reporting the issue. Does it repro frequently? Please share a dump (multiple if available) via email if possible.

  7. pavel-faltynek commented on Dec 5, 2024

    @pavel-faltynek
    Author

    Yes, it fails periodically (but have no clue, what is the exact trigger). We have systemd managed 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).

  8. pavel-faltynek commented on Dec 6, 2024

    @pavel-faltynek
    Author

    I have tried the trivial dotnet new webapi, dotnet new webapiaot directly on the target system (curling over http/https), additionally adding explicit request to invoke GC.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 $output
    For the reported case, $framework = 'net9.0', $runtime = 'linux-arm64'.

  9. mangod9 commented on Dec 6, 2024

    @mangod9
    Member

    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.

  10. jkoritzinsky commented on Dec 7, 2024

    @jkoritzinsky
    Member

    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 Thread object 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.

  11. mangod9 commented on Dec 7, 2024

    @mangod9
    Member

    In this particular case doesnt look like it's occurring during shutdown. I have shared the dump with you offline.

  12. jkotas commented on Dec 9, 2024

    @jkotas
    Member

    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?

  13. pavel-faltynek commented on Dec 9, 2024

    @pavel-faltynek
    Author

    @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.

  14. pavel-faltynek commented on Dec 9, 2024

    @pavel-faltynek
    Author

    @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:

    • dump number 3 (just redeployed and wait for crash, so no explicit request, only balancer health checks), looks a bit different:
    [0x0]   libcoreclr!Object::RawSetMethodTable   (Inline Function)   (Inline Function)   
    [0x1]   libcoreclr!SVR::CObjectHeader::SetFree+0x10   (Inline Function)   (Inline Function)   
    [0x2]   libcoreclr!SVR::gc_heap::make_unused_array+0x5c   0xffff619964d0   0xffffa406cb30   
    [0x3]   libcoreclr!SVR::gc_heap::fix_allocation_context+0x64   (Inline Function)   (Inline Function)   
    [0x4]   libcoreclr!SVR::GCHeap::FixAllocContext+0xf0   0xffff61996540   0xffffa3f594f8   
    [0x5]   libcoreclr!GCToEEInterface::GcEnumAllocContexts+0x54   0xffff61996570   0xffffa4026210   
    [0x6]   libcoreclr!SVR::gc_heap::fix_allocation_contexts+0x28   (Inline Function)   (Inline Function)   
    [0x7]   libcoreclr!SVR::gc_heap::garbage_collect+0x60   0xffff619965a0   0xffffa4023f44   
    [0x8]   libcoreclr!SVR::gc_heap::gc_thread_function+0xca8   0xffff61996670   0xffffa402329c   
    [0x9]   libcoreclr!SVR::gc_heap::gc_thread_stub+0x38   0xffff619966f0   0xffffa3f5c420   
    [0xa]   libcoreclr!<unnamed-namespace>::CreateNonSuspendableThread::$_0::operator()+0x3c   (Inline Function)   (Inline Function)   
    [0xb]   libcoreclr!<unnamed-namespace>::CreateNonSuspendableThread::$_0::__invoke+0x50   0xffff61996710   0xffffa424afb0   
    [0xc]   libcoreclr!CorUnix::CPalThread::ThreadEntry+0x1b8   0xffff61996740   0xffffa44ed5c8   
    [0xd]   libc_so+0x7d5c8   0xffff61996800   0x0   
    
    • dump number 4, 5 (looks "standard"):
    [0x0]   libcoreclr!alloc_context::init_alloc_count   (Inline Function)   (Inline Function)   
    [0x1]   libcoreclr!SVR::GCHeap::FixAllocContext+0x14   0xffff559a6540   0xffff97f694f8   
    [0x2]   libcoreclr!GCToEEInterface::GcEnumAllocContexts+0x54   0xffff559a6570   0xffff98036210   
    [0x3]   libcoreclr!SVR::gc_heap::fix_allocation_contexts+0x28   (Inline Function)   (Inline Function)   
    [0x4]   libcoreclr!SVR::gc_heap::garbage_collect+0x60   0xffff559a65a0   0xffff98033f44   
    [0x5]   libcoreclr!SVR::gc_heap::gc_thread_function+0xca8   0xffff559a6670   0xffff9803329c   
    [0x6]   libcoreclr!SVR::gc_heap::gc_thread_stub+0x38   0xffff559a66f0   0xffff97f6c420   
    [0x7]   libcoreclr!<unnamed-namespace>::CreateNonSuspendableThread::$_0::operator()+0x3c   (Inline Function)   (Inline Function)   
    [0x8]   libcoreclr!<unnamed-namespace>::CreateNonSuspendableThread::$_0::__invoke+0x50   0xffff559a6710   0xffff9825afb0   
    [0x9]   libcoreclr!CorUnix::CPalThread::ThreadEntry+0x1b8   0xffff559a6740   0xffff984fd5c8   
    [0xa]   libc_so+0x7d5c8   0xffff559a6800   0x0   
    
  15. 25 remaining items

  16. pavel-faltynek commented on Jan 3, 2025

    @pavel-faltynek
    Author

    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).

  17. janvorli commented on Jan 3, 2025

    @janvorli
    Member

    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.

    THREAD  TIMESTAMP     FACILITY                              MESSAGE
      ID  (sec from start)
    --------------------------------------------------------------------------------------
    310c01 18444492303.728168488 : `STARTUP`            Thread is being reinitialized after cleanup
    310c01 18444492303.728153229 : `ALWAYS`             SetupThread  managed Thread 0xffbeb024e9e0 Thread Id = 5
    
  18. janvorli commented on Jan 3, 2025

    @janvorli
    Member

    And the caller of the JIT_ReversePInvokeEnterRare in the call stack dumped above was MailClient.Push.Api.MemoryAllocationsTracker.CryptoFree(Void*)

  19. dotnet-policy-service commented on Jan 9, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @mangod9
    See info in area-owners.md if you want to be subscribed.

  20. modified the milestones: 10.0.0, Future on Jan 28, 2025
  21. kouvel commented on Jan 28, 2025

    @kouvel
    Contributor

    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_local variables 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?

  22. jkotas commented on Jan 28, 2025

    @jkotas
    Member

    @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?

  23. kouvel commented on Jan 29, 2025

    @kouvel
    Contributor

    Can we detect an attempt to re-initialize the runtime thread object and abort immediately to make this issue easier to diagnose next time?

    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_local vars on macOS after they have been destroyed.

  24. jkotas commented on Jan 29, 2025

    @jkotas
    Member

    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.

  25. pavel-faltynek commented on Feb 4, 2025

    @pavel-faltynek
    Author

    @pavel-faltynek, it sounds like you were able to work around the problem. Can this issue be closed?

    Yes. Thank you all for sorting it out.

  26. locked and limited conversation to collaborators on Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions