Skip to content

Report DSC execution diagnostics on a timer#6196

Open
JohnMcPMS wants to merge 2 commits intomicrosoft:masterfrom
JohnMcPMS:dsc-hang
Open

Report DSC execution diagnostics on a timer#6196
JohnMcPMS wants to merge 2 commits intomicrosoft:masterfrom
JohnMcPMS:dsc-hang

Conversation

@JohnMcPMS
Copy link
Copy Markdown
Member

@JohnMcPMS JohnMcPMS commented May 2, 2026

Change

To investigate why dsc appears to start hanging with 3.2.0, output dsc lines in batches on a timer rather than after the process has exited.

Microsoft Reviewers: Open in CodeFlow

JohnMcPMS and others added 2 commits May 1, 2026 16:56
ProcessExecution already fired OutputLineReceived/ErrorLineReceived
events per line as data arrived from the async stream readers, but
RunSynchronously() never subscribed to them -- instead dumping all
buffered output in one diagnostic message only after the process
exited. If dsc.exe hangs, nothing appears in the log until (or
unless) the process terminates.

Add ProcessOutputBatcher, a thread-safe helper that:
- Subscribes to ProcessExecution's stream events
- Accumulates [out]/[err]-prefixed lines in a StringBuilder under a lock
- Flushes the buffer to IDiagnosticsSink as a single batched message
  on a 500ms timer, so output appears promptly without one IPC call
  per line
- Exposes Flush() to drain remaining lines after WaitForExit()

Wire it into RunSynchronously(): the post-exit diagnostic now logs
only the exit code (content has already been streamed).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JohnMcPMS JohnMcPMS requested a review from a team as a code owner May 2, 2026 05:27
this.buffer = new StringBuilder();
}

this.sink.OnDiagnostics(DiagnosticLevel.Verbose, this.batchHeader + toEmit);
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.

Why do we need a batch header for every tick?

foreach (string line in lines)
{
stringBuilder.AppendLine(line);
stringBuilder.Append(line).Append('\n');
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.

Why not AppendLine() anymore? And why not Environment.NewLine?

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