Skip to content

Commit

Permalink
[release/8.0-rc2] Do not call SignalSession on invalid session IDs (#…
Browse files Browse the repository at this point in the history
…92444)

* Update EventPipeEventDispatcher.cs

* Update EventPipeEventDispatcher.cs

---------

Co-authored-by: David Mason <davmason@microsoft.com>
  • Loading branch information
github-actions[bot] and davmason committed Sep 22, 2023
1 parent 0717e52 commit 873b3cc
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,15 @@ private void SetStopDispatchTask()
{
Debug.Assert(Monitor.IsEntered(m_dispatchControlLock));

if (m_dispatchTask != null)
if (m_dispatchTaskCancellationSource?.IsCancellationRequested ?? true)
{
Debug.Assert(m_dispatchTaskCancellationSource != null);
m_dispatchTaskCancellationSource?.Cancel();
EventPipeInternal.SignalSession(m_sessionID);
return;
}

Debug.Assert(m_sessionID != 0);
m_dispatchTaskCancellationSource.Cancel();
EventPipeInternal.SignalSession(m_sessionID);
m_sessionID = 0;
}

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

// Disable the old session. This can happen asynchronously since we aren't using the old session anymore
EventPipeInternal.Disable(sessionID);
lock (m_dispatchControlLock)
{
// Disable the old session. This can happen asynchronously since we aren't using the old session
// anymore. We take the lock to make sure we don't call SignalSession on an invalid session ID.
EventPipeInternal.Disable(sessionID);
}
}

/// <summary>
Expand Down

0 comments on commit 873b3cc

Please sign in to comment.