Skip to content

Commit 873b3cc

Browse files
[release/8.0-rc2] Do not call SignalSession on invalid session IDs (#92444)
* Update EventPipeEventDispatcher.cs * Update EventPipeEventDispatcher.cs --------- Co-authored-by: David Mason <[email protected]>
1 parent 0717e52 commit 873b3cc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,15 @@ private void SetStopDispatchTask()
142142
{
143143
Debug.Assert(Monitor.IsEntered(m_dispatchControlLock));
144144

145-
if (m_dispatchTask != null)
145+
if (m_dispatchTaskCancellationSource?.IsCancellationRequested ?? true)
146146
{
147-
Debug.Assert(m_dispatchTaskCancellationSource != null);
148-
m_dispatchTaskCancellationSource?.Cancel();
149-
EventPipeInternal.SignalSession(m_sessionID);
147+
return;
150148
}
149+
150+
Debug.Assert(m_sessionID != 0);
151+
m_dispatchTaskCancellationSource.Cancel();
152+
EventPipeInternal.SignalSession(m_sessionID);
153+
m_sessionID = 0;
151154
}
152155

153156
private unsafe void DispatchEventsToEventListeners(ulong sessionID, DateTime syncTimeUtc, long syncTimeQPC, long timeQPCFrequency, Task? previousDispatchTask, CancellationToken token)
@@ -187,8 +190,12 @@ private unsafe void DispatchEventsToEventListeners(ulong sessionID, DateTime syn
187190
}
188191
}
189192

190-
// Disable the old session. This can happen asynchronously since we aren't using the old session anymore
191-
EventPipeInternal.Disable(sessionID);
193+
lock (m_dispatchControlLock)
194+
{
195+
// Disable the old session. This can happen asynchronously since we aren't using the old session
196+
// anymore. We take the lock to make sure we don't call SignalSession on an invalid session ID.
197+
EventPipeInternal.Disable(sessionID);
198+
}
192199
}
193200

194201
/// <summary>

0 commit comments

Comments
 (0)