perfview
perfview copied to clipboard
"A CLR Profiler has already been attached" after few run with ForceGC
I used "HeapDump /ForceGC" directly to trigger GC on some process periodically. However I noticed that after it runs few times it start to throw errors like this:
"A CLR Profiler has already been attached. You cannot attach another. (a process restart will fix)"
The problem is that I need keep the process running, e.g. w3wp process from iis. Is there anyway to find out why the profiler is still attached and how to detach it if possible?
Seems that the w3wp process is still having EtwClrProfiler.dll loaded after HeapDump quits.
@bigbearzhu you have to tear down the process, the dll once loaded in a certain way (i.e. from process startup) will always have it attached.
It is not attached at process startup. It is attached when HeapDump runs and detached after it finishes. It succeeds for a few times, and then start to fail to detach for some reason. Had a look at CorProfilerTracer.cpp line 298:
if ((MatchAnyKeywords & DetachKeyword) != 0 && !m_profilerLoadedAtStartup && !m_detaching)
Could m_profilerLoadedAtStartup be true when detaching so it is not detached?
https://msdn.microsoft.com/en-us/library/dd997942(v=vs.100).aspx#attach_details
Within the target process, the procedure for loading a profiler at attach-time is similar to the procedure for loading a profiler at startup-time: The CLR
CoCreates
the given CLSID, queries for theICorProfilerCallback3
interface, and calls theICorProfilerCallback3::InitializeForAttach
method.
looked into the log of the EtwClrProfiler.dll. Seems it is getting error when trying to detach the profiler:
Creating new CorProfilerInstance
ClrProfiler Initializing
Registering the ETW provider
Initialize() returns 0
ProfilerControlCallback DoETWCommand IsEnabled 0x2 Level 0x5I64 MatchAny 0x0
DoETWCommand(IsEnabled=2, Level=5 Keywords=0x8000,0)
Detaching
Done Detaching Detaching ret = 0x80131363
while a successful detaching log is like this:
Creating new CorProfilerInstance
ClrProfiler Initializing
Registering the ETW provider
Initialize() returns 0
ProfilerControlCallback DoETWCommand IsEnabled 0x2 Level 0x5I64 MatchAny 0x0
DoETWCommand(IsEnabled=2, Level=5 Keywords=0x8000,0)
Detaching
Done Detaching Detaching ret = 0x0
ProfilerDetachSucceeded
Shutdown
Destroying CorProfilerInstance
As far as I can find, 0x80131363 is CORPROF_E_UNSUPPORTED_CALL_SEQUENCE as from here which I totally have no clue how that could happen and be solved. :(
I landed here because I have the same issue when attempting to force GC on w3wp
I have same issue found on a different process (unrelated to w3wp). Mine is a very thread-hungry process, in case that rings some bells.