Skip to content

Conversation

SteveL-MSFT
Copy link
Member

PR Summary

Found this while working on MCP tool. On Windows, if you do:

dsc resource list | select-object -first 1

dsc will emit JSON lines and after the first line, the cmdlet causes the pipeline to close therefore closing STDOUT for the dsc process. Without this change, it attempts to write to a broken pipe and crashes. On Unix systems, a signal is sent to the process to exit so it doesn't attempt to write to a broken pipe.

@SteveL-MSFT SteveL-MSFT requested review from tgauth and Copilot October 3, 2025 00:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a crash on Windows when the output pipe is closed by shell commands like select-object -first 1. The fix adds proper error handling for broken pipe scenarios to ensure the process exits gracefully instead of crashing.

  • Adds error handling for broken pipe scenarios when writing to stdout
  • Implements graceful exit with success code when pipe is closed early
  • Adds test coverage for the broken pipe scenario

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dsc/src/util.rs Replaces println! with explicit stdout write and error handling for broken pipes
dsc/tests/dsc.exit_code.tests.ps1 Adds test case to verify graceful exit when pipe is closed early

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@SteveL-MSFT SteveL-MSFT merged commit f272f86 into PowerShell:main Oct 6, 2025
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the broken-pipe branch October 6, 2025 19:37
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.

1 participant