Skip to content

Fix crash when disposing DAC after self-attach on Linux (#1282)#1361

Open
leculver wants to merge 2 commits intomicrosoft:mainfrom
leculver:issue_1282
Open

Fix crash when disposing DAC after self-attach on Linux (#1282)#1361
leculver wants to merge 2 commits intomicrosoft:mainfrom
leculver:issue_1282

Conversation

@leculver
Copy link
Contributor

On non-Windows platforms, calling dlclose on the DAC library (libmscordaccore.so) after inspecting the current process crashes the CLR. The DAC shares internal state with the running CLR, and unloading it corrupts that state, causing a SIGSEGV in libcoreclr.so.

This fix suppresses FreeLibrary on the DAC when the target process matches the current process ID on non-Windows platforms.

Fixes #1282

On non-Windows platforms, calling dlclose on the DAC library (libmscordaccore.so)
after inspecting the current process crashes the CLR. The DAC shares internal
state with the running CLR, and unloading it corrupts that state, causing a
SIGSEGV in libcoreclr.so.

This fix suppresses FreeLibrary on the DAC when the target process matches the
current process ID on non-Windows platforms.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Linux/macOS self-attach crash caused by unloading the DAC native library (dlclose/FreeLibrary) after CreateRuntime, by allowing DAC unloading to be suppressed when the target PID is the current process.

Changes:

  • Added an option to suppress FreeLibrary in RefCountedFreeLibrary.
  • Updated DacLibrary to suppress unloading the DAC on non-Windows platforms when inspecting the current process.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Microsoft.Diagnostics.Runtime/RefCountedFreeLibrary.cs Adds a suppression flag to prevent unloading the native library on final Release.
src/Microsoft.Diagnostics.Runtime/DacLibrary.cs Detects non-Windows self-attach and uses the new suppression flag to avoid dlclose of the DAC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLR crashes soon after CreateRuntime called on Linux

1 participant

Comments