Skip to content

Honor StopProcessing in EventPipeEventSource - #2497

Merged
Brian Robbins (brianrob) merged 1 commit into
microsoft:mainfrom
pcshrosbree:fix/eventpipe-stopprocessing
Oct 26, 2026
Merged

Brian Robbins (brianrob) merged 1 commit into
microsoft:mainfrom
pcshrosbree:fix/eventpipe-stopprocessing

Conversation

@pcshrosbree

Copy link
Copy Markdown
Contributor

TL;DR: EventPipeEventSource ignores StopProcessing(). This PR makes it stop dispatching after the call and return false from Process(), as TraceEventDispatcher documents. The change is in one file, plus three tests.

After a callback calls StopProcessing(), the source keeps dispatching events to the end of the stream, and Process() still returns true. On a live session it keeps reading, so Process() does not return while events keep arriving. TraceEventDispatcher.StopProcessing() documents that the stop takes effect at the next event, and Process() documents that it then returns false.

The edits, all in EventPipeEventSource.cs:

  • DispatchEvent returns without dispatching once stopProcessing is set. Every data event goes through it, whatever the format version and whether or not it was sorted through the EventCache.
  • BlockParser.ParseRemainder finishes the current block and its footer, then checks the stop flag before reading another block.
  • Process() then calls EventCache.Flush(), the same cleanup that runs at the end of the stream, with dispatch still suppressed, and returns false.
  • The 24-hour sanity check on event timestamps in ReadEventHeader is skipped after a stop, because sessionEndTimeQPC no longer advances for the rest of the block.

Nothing changes when StopProcessing() isn't called. Calling StopProcessing() while Process() is waiting for data on a quiet live session does not interrupt that wait. Data must still arrive or the session must be stopped before Process() can return, as the StopProcessing() documentation describes.

I ran the following on Linux x64. I built TraceEvent.Tests and the patched library with .NET SDK 10.0.402. I built the standalone repro with SDK 10.0.401 and ran it on .NET 10.0.12.

  • Three new tests in EventPipeParsing.cs, run in Debug so the assertions are active. One uses a NetTrace V5 stream. One uses a NetTrace V6 stream with an event still queued and no end block, so reading another block would fail; it also checks that the cache holds no event buffers afterwards. The third uses a V6 stream. One event's callback calls StopProcessing(). Later events have timestamps 12 hours and just over 24 hours after that event. All three fail without this change and pass with it. Removing any one of the four edits makes at least one of them fail.
  • TraceEvent.Tests on net10.0, in Debug: apart from the three new tests, the same 133 tests fail on Linux with and without this change. I didn't run net462.
  • A standalone repro: a process that traces itself through DiagnosticsClient. With TraceEvent 4.0.0 from NuGet, StopProcessing() in the first callback over a recorded .nettrace is followed by all 999 remaining callbacks. On a live session with an event every millisecond, StopProcessing() in the 10th callback is followed by about 2,800 callbacks over the next 3 seconds, and Process() does not return. TraceEvent 3.2.4 and 3.2.8 behave the same. With this change, no callback follows StopProcessing() in either case, and Process() returns false (on the live session, within 3 seconds).

EventPipeEventSource never read the stopProcessing flag. After
StopProcessing(), it kept dispatching events until the end of the
stream, and Process() always returned true. On a live session it kept
reading, so StopProcessing() had no effect.

Skip dispatch once the flag is set, stop reading after the current
block, and return false from Process(), as TraceEventDispatcher
documents. Before returning, call EventCache.Flush(), the cleanup
that runs at the end of the stream, with dispatch still suppressed.
After a stop, skip the 24-hour timestamp sanity check in
ReadEventHeader, since sessionEndTimeQPC no longer advances for the
rest of the block.

@brianrob Brian Robbins (brianrob) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for contributing this.

@brianrob
Brian Robbins (brianrob) merged commit 9f071a5 into microsoft:main Oct 26, 2026
5 checks passed
@pcshrosbree

Copy link
Copy Markdown
Contributor Author

Thank you for the review and merge!

This was referenced Nov 21, 2026
Nick Moger (nubbymong) added a commit to nubbymong/poolwatch that referenced this pull request Nov 27, 2026
Updated
[Microsoft.Diagnostics.Tracing.TraceEvent](https://github.com/Microsoft/perfview)
from 4.0.0 to 4.0.2.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Diagnostics.Tracing.TraceEvent's
releases](https://github.com/Microsoft/perfview/releases)._

## 4.0.2

## What's Changed
* Fix Capitalize in GetManifestForRegisteredProvider event names by
@​jdu2600 in microsoft/perfview#2481
* Update .NET SDK To 10.0.402 by @​brianrob in
microsoft/perfview#2494
* Fix `GetManifestForRegisteredProvider` returning wrong event details
for `EventlogClassic` events. by @​jdu2600 in
microsoft/perfview#2482
* Label GetManifestForRegisteredProvider's string table with
CurrentUICulture by @​jdu2600 in
microsoft/perfview#2488
* Reduce ETLX conversion memory with compact stack indexes by
@​JeremyKuhne in microsoft/perfview#2485
* Use bulk copying in GrowableArray.RemoveRange by @​JeremyKuhne in
microsoft/perfview#2489
* Select Processes Before Building ETL And EventPipe Stack Sources by
@​brianrob in microsoft/perfview#2496
* Fix Unsigned Integer Decoding In TDH Payloads by @​brianrob in
microsoft/perfview#2495
* Honor StopProcessing in EventPipeEventSource by @​pcshrosbree in
microsoft/perfview#2497
* Validate Scenario Export Output File Names by @​brianrob in
microsoft/perfview#2504
* Skip Predefined Template Lookups For Unrelated EventPipe Providers by
@​brianrob in microsoft/perfview#2503
* Avoid Allocating Predefined Dynamic Parser Lookup Keys by @​brianrob
in microsoft/perfview#2502
* Increase File-Backed Serialization Buffer To Reduce ETLX Write
Overhead by @​brianrob in
microsoft/perfview#2505
* Fix Hidden PDB Trust Dialog After Switching Applications by @​brianrob
in microsoft/perfview#2507
* Fix reserved keyword threshold in GetManifestForRegisteredProvider by
@​jdu2600 in microsoft/perfview#2509
* Validate Event Payload Fields, Strings, Arrays, And Related-Activity
GUIDs
* Validate BPerf Session Headers, Compressed Blocks, And Decompression
Bounds
* Require Complete CTF Reads And Validate Array Sizes And Payload
Lengths
* Bound Captured Packet Headers And TCP Options While Preserving Non-IP
And Fragment Handling
* Validate PE Cache Ranges And Require Complete Pointer Reads
* Decode Kernel TCP Connection IDs And Sequence Numbers According To
Event Version

## New Contributors
* @​jdu2600 made their first contribution in
microsoft/perfview#2481
* @​pcshrosbree made their first contribution in
microsoft/perfview#2497

**Full Changelog**:
microsoft/perfview@v4.0.0...v4.0.2


Commits viewable in [compare
view](microsoft/perfview@v4.0.0...v4.0.2).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Diagnostics.Tracing.TraceEvent&package-manager=nuget&previous-version=4.0.0&new-version=4.0.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: nubbymong <192402368+nubbymong@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants