Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fce15e5

Browse files
kouvelKoundinya Veluri
authored andcommitted
Fix nested spin locks in thread pool etw firing (#17677)
Port of #17677 to 2.2 `UnManagedPerAppDomainTPCount::QueueUnmanagedWorkRequest` fires an ETW event inside a spin lock and a nested spin lock is taken here: ``` SpinLock::GetLock + 0x8E (0x719da71d) EventPipeBufferManager::AllocateBufferForThread + 0x7B (0x71afa92e) EventPipeBufferManager::WriteEvent + 0x250 (0x71afbe0a) EventPipe::WriteEventInternal + 0x125 (0x71951c93) EventPipe::WriteEvent + 0x91 (0x71951714) EventPipeWriteEventThreadPoolEnqueue + 0x9E (0x71d468a6) FireEtwThreadPoolEnqueue + 0xF (0x71b7a04b) UnManagedPerAppDomainTPCount::QueueUnmanagedWorkRequest + 0x21D (0x71b7a597) ``` Nesting spin locks is not allowed, moved the ETW firing outside the lock.
1 parent 98a7f87 commit fce15e5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/vm/threadpoolrequest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,15 @@ void UnManagedPerAppDomainTPCount::QueueUnmanagedWorkRequest(LPTHREAD_START_ROUT
420420
_ASSERTE(pWorkRequest != NULL);
421421
PREFIX_ASSUME(pWorkRequest != NULL);
422422

423+
if (ETW_EVENT_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context, ThreadPoolEnqueue) &&
424+
!ThreadpoolMgr::AreEtwQueueEventsSpeciallyHandled(function))
425+
FireEtwThreadPoolEnqueue(pWorkRequest, GetClrInstanceId());
426+
423427
m_lock.Init(LOCK_TYPE_DEFAULT);
424428

425429
{
426430
SpinLock::Holder slh(&m_lock);
427431

428-
if (ETW_EVENT_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context, ThreadPoolEnqueue) &&
429-
!ThreadpoolMgr::AreEtwQueueEventsSpeciallyHandled(function))
430-
FireEtwThreadPoolEnqueue(pWorkRequest, GetClrInstanceId());
431432
ThreadpoolMgr::EnqueueWorkRequest(pWorkRequest);
432433
pWorkRequest.SuppressRelease();
433434
m_NumRequests++;

0 commit comments

Comments
 (0)