Skip to content

PerfMap Reenable Crashing from AssemblyIterator IterateAssembliesEx #123438

@mdh1418

Description

@mdh1418

Description

PerfMap allows re-enabling through the DiagnosticServer IPC Command PerfMapEnable.
Doing so early in startup (e.g. userevents tests) has led to crashes such as #122472 and the following

00 0000f12a`161eeae0 0000f12a`15b4f918     libc_so+0xd5154
01 0000f12a`161eeb10 0000f12a`15b503c8     libcoreclr!PROCCreateCrashDump+0x510 [/__w/1/s/src/coreclr/pal/src/thread/process.cpp @ 2573] 
02 0000f12a`161eeb90 0000f12a`15b1a8e0     libcoreclr!PROCCreateCrashDumpIfEnabled+0x320 [/__w/1/s/src/coreclr/pal/src/thread/process.cpp @ 2822] 
03 0000f12a`161eed00 0000f12a`15b19b5c     libcoreclr!invoke_previous_action+0x1ac [/__w/1/s/src/coreclr/pal/src/exception/signal.cpp @ 439] 
04 0000f12a`161eed50 0000f12a`1627f7a0     libcoreclr!sigsegv_handler+0x1c8
05 0000f12a`161eeda0 0000f12a`157e6458     linux_vdso_so!_kernel_rt_sigreturn
06 (Inline Function) --------`--------     libcoreclr!AppDomain::AssemblyIterator::Create+0x24 [/__w/1/s/src/coreclr/vm/appdomain.hpp @ 1022] 
07 (Inline Function) --------`--------     libcoreclr!AppDomain::IterateAssembliesEx+0x24 [/__w/1/s/src/coreclr/vm/baseassemblyspec.h @ 1032] 
08 0000f129`d4a1e460 0000f12a`1552c7cc     libcoreclr!PerfMap::Enable+0x1a8 [/__w/1/s/src/coreclr/inc/sstring.h @ 124] 
09 (Inline Function) --------`--------     libcoreclr!ds_rt_enable_perfmap+0x18 [/__w/1/s/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h @ 317] 
0a (Inline Function) --------`--------     libcoreclr!process_protocol_helper_enable_perfmap+0x80 [/__w/1/s/src/native/eventpipe/ds-portable-rid.c @ 1072] 
0b 0000f129`d4a1e640 0000f12a`155315e8     libcoreclr!ds_process_protocol_helper_handle_ipc_message+0x31c [/__w/1/s/src/native/eventpipe/ds-portable-rid.c @ 1245] 
0c (Inline Function) --------`--------     libcoreclr!server_loop_tick+0x198 [/__w/1/s/src/native/eventpipe/ds-server.c @ 158] 
0d 0000f129`d4a1e7e0 0000f12a`15b52d98     libcoreclr!server_thread+0x270 [/__w/1/s/src/native/eventpipe/ds-protocol.c @ 185] 
0e 0000f129`d4a1e860 0000f12a`15ce0944     libcoreclr!CorUnix::CPalThread::ThreadEntry+0x350 [/__w/1/s/src/coreclr/pal/src/thread/thread.cpp @ 1601] 
0f 0000f129`d4a1e920 0000f12a`15d46ccc     libc_so+0x80944
10 0000f129`d4a1ea40 ffffffff`ffffffff     libc_so+0xe6ccc
11 0000f129`d4a1ea40 00000000`00000000     0xffffffff`ffffffff

This crash, after bumping PerfMap::Initialize earlier in start-up, reveals that PerfMap Reenable (sendExisting=true) assumes that the command is only sent once AppDomain's AssemblyIterator is able to IterateAssembliesEx.

This is a seldomly hit scenario rather than a regression. Its only being hit now because userevents tests spin up RecordTrace before starting tracee apps and RecordTrace identifies .NET processes and sends a PerfMap Enable IPC Command as early as possible.

The fix is likely gracefully handling assembly iteration at

AppDomain::AssemblyIterator assemblyIterator = GetAppDomain()->IterateAssembliesEx(
(AssemblyIterationFlags)(kIncludeLoaded | kIncludeExecution));

Reproduction Steps

Send Enable PerfMap IPC command early in startup

Expected behavior

No crash

Actual behavior

Crashes

Regression?

No

Known Workarounds

Don't send IPC command early in app startup

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions