dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.98k stars 4.66k forks source link

Random crash in native aot runtime code on win-x86 #107506

Open ksharperd opened 1 week ago

ksharperd commented 1 week ago

Description

Load a native aot binary compiled with win-x86 cause randomly crash during executing.

i'm using runtime commit https://github.com/dotnet/runtime/commit/af1b39a3d8bb2221ab1021f20ba6f87ef9c5c9ef which obtained from https://github.com/dotnet/sdk/blob/main/documentation/package-table.md

stackstrace

crashdump

Reproduction Steps

Pulish a library with native aot using win-x86.

Load compiled binary into target process.

Wait util gc was triggered.

Expected behavior

Run without any error.

Actual behavior

Randomly crash.

Regression?

No response

Known Workarounds

No

Configuration

.NET SDK: Version: 9.0.100-rc.2.24457.1 Commit: c80faea95e Workload version: 9.0.100-manifests.cd3e05ac MSBuild version: 17.12.0-preview-24453-06+d4242542e Microsoft.NETCore.App: 9.0.0-rc.2.24454.7

OS: Windows 10 Build 19045

Other information

No response

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.

jkotas commented 1 week ago

Are you able to reproduce this crash reliably?

Crash with this stacktrace can be caused by some other code in the process terminating a thread that run managed code using TerminateThread. TerminateThread is a dangerous API as its documentation explains. Native AOT is not compatible with this API being used to terminate a thread that run native AOT compiled code.

Could you please check whether the TerminateThread API was called? E.g. run the repro under debugger and set a breakpoint on kernelbase!TerminateThread.

ksharperd commented 1 week ago

Are you able to reproduce this crash reliably?

Crash with this stacktrace can be caused by some other code in the process terminating a thread that run managed code using TerminateThread. TerminateThread is a dangerous API as its documentation explains. Native AOT is not compatible with this API being used to terminate a thread that run native AOT compiled code.

Could you please check whether the TerminateThread API was called? E.g. run the repro under debugger and set a breakpoint on kernelbase!TerminateThread.

i set a execution breakpont on kernelbase!TerminateThread and confirmed that this api won't be call.

jkotas commented 1 week ago

crashdump

Could you please share the .pdb file for the crash dump if possible? The crash dump is impossible to reasonably debug without the .pdb file.

ksharperd commented 1 week ago

crashdump

Could you please share the .pdb file for the crash dump if possible? The crash dump is impossible to reasonably debug without the .pdb file.

sure, newly created crashdump+pdb.
don't know if this pdb is enough.