Fix OOP pcap capture race with archive packaging#626
Merged
Conversation
Dispose the capture scope before PackDirectoryToFile so the subprocess closes its pcapng FileStreams and flushes buffered data to disk. Previously the scope was method-scoped and disposed after packaging, so small captures could sit in the 4KB FileStream buffer and get skipped by ZipHelper's Length==0 check, leaving captures/*.pcapng missing from the fxzy archive. Also flush the BinaryWriter in OutOfProcessCaptureContext.Flush so the flush message actually reaches the subprocess, and tighten the CLI test assertion to Assert.NotNull before draining the capture stream.
This was referenced Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The out-of-proc capture subprocess held pcapng
FileStreams with buffered data whilePackDirectoryToFilezipped the capture directory. Small captures could sit in the 4KBFileStreambuffer and get skipped byZipHelper'sLength == 0check, leavingcaptures/*.pcapngmissing from the fxzy archive. This caused intermittent NREs inCliWithCapOutOfProc.Runwhen the test drained the (null) raw capture stream.Changes
StartCommandBuilder: wrapscopein anawait usingblock so the capture subprocess exits (closing and flushing all pcapngFileStreams) before packaging runs.OutOfProcessCaptureContext.Flush: actually flush theBinaryWriterso the flush message reaches the subprocess.CliTestBase: assertNotNullon the raw capture stream before draining so future regressions surface with a clear message instead of an NRE through an extension method.