Skip to content

Profiler use after release on process exit #11885

@iskiselev

Description

@iskiselev

CoreCLR version: 2.1, 2.2 (probably all of them)
OS: Ubuntu/CentOs/MacOs (probably any non-Windows)

On application exit CLR sometimes crashes with SEGFAULT if profiler has subscribed to COR_PRF_MONITOR_JIT_COMPILATION.
Based on coredump analysis crash happened in EEToProfInterfaceImpl::JITCompilationStarted(unsigned long, int) ().
Looks like it is possible to crash on other profiler callback too - but was not able to stable reproduce with other, but colleague reported that it was observed once on ModuleUnloadFinished.
We've started investigation on it, as have seen exit code 1 sometimes from dotnet test run with XUnit test, after test reported that all test passed successfully on Linux CI environment. We've never seen it on Windows CI environment.

After further investigation, looks like it is enough that profiler will do nothing except:

  • SetEventMask(COR_PRF_MONITOR_JIT_COMPILATION | COR_PRF_DISABLE_ALL_NGEN_IMAGES | COR_PRF_DISABLE_OPTIMIZATIONS | COR_PRF_DISABLE_INLINING) inside Initialize
  • return S_OK for all callbacks
  • proper implement AddRef / Release with deleting itself if ref count = 0.

The issue can be stable reproduced with XUnit tests (one test that will do nothing is enough).
After first execution of dotnet test, I've repeated execution of dotnet exec /usr/share/dotnet/sdk/<version>/vstest.console.dll --framework:.NETCoreApp,Version=v2.0 --logger:trx --Diag:TestResults/testDiagnostics.txt <path_to_test>/Release/netcoreapp2.0/<testname>.dll
It fails after ~20 executions with segfault and exit code 139.

I can provide sample application/profiler, but it will require some additional work on my side.

When I've looked on coreclr sources, I've found very suspicious place here: https://github.com/dotnet/coreclr/blob/a28b25aacdcd2adb0fdfa70bd869f53ba6565976/src/vm/profilinghelper.cpp#L1304
IsProfilerEvacuated check is done only when FEATURE_PROFAPI_ATTACH_DETACH enabled, which may be a hint why have we seen problem only on non-Windows OS.

CC: @noahfalk

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions