Skip to content

Report DSC execution diagnostics on a timer#6196

Merged
JohnMcPMS merged 4 commits intomicrosoft:masterfrom
JohnMcPMS:dsc-hang
May 7, 2026
Merged

Report DSC execution diagnostics on a timer#6196
JohnMcPMS merged 4 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
florelis
florelis previously approved these changes May 4, 2026
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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nothing guarantees that this is not intermingled with other diagnostics; the header contains the process number.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because what ended up being in the log file was \r\r\n and VS Code was showing that as two lines. I did not attempt to find out exactly why that was happening.

… fix for the hang: default to redirecting input
@JohnMcPMS JohnMcPMS merged commit 5c03e8b into microsoft:master May 7, 2026
9 checks passed
@JohnMcPMS JohnMcPMS deleted the dsc-hang branch May 7, 2026 00:47
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