Skip to content

PowerShell commands run to completion even with a broken pipe to an external (native) program #8420

Closed

Description

Note: The issue isn't specific to Unix, as originally stated - see #15329

... | Select-Object -First 1 stops the upstream command after receiving the 1st input object, but the same is not true when the sink is an external program:

Steps to reproduce

1..10 | Write-Output -ov result | head -n 1; $result.Count

Expected behavior

1
1

Actual behavior

1
10

That is, Write-Output unexpectedly ran to completion, even though head exited after receiving the first input line, making it pointless to send additional objects to the pipeline.

Environment data

PowerShell Core v6.2.0-preview.2 on macOS 10.14.1
PowerShell Core v6.2.0-preview.2 on Ubuntu 18.04.1 LTS

Activity

  1. KevinMarquette commented on Dec 8, 2018

    @KevinMarquette
    Contributor

    In this case, Select-Object manipulating the pipeline to make this happen. I'm not sure if an external program would be able to do the same. In the current implementation it looks like it would be up to the external program to handle this.

    src/Microsoft.PowerShell.Commands.Utility/commands/utility/select-object.cs#L692

  2. iSazonov commented on Dec 8, 2018

    @iSazonov
    Collaborator

    I am not sure that the external command terminates after reading first item. I guess it collects all input. Can we use our TestExe for check?

  3. added
    WG-Enginecore PowerShell engine, interpreter, and runtime
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Dec 8, 2018
  4. mklement0 commented on Dec 8, 2018

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov): head is designed to exit once it has received enough input; doing so leaves the pipe broken, and when the process on the writing end tries to write to the pipe the next time, it normally receives a SIGPIPE signal, or, if SIGPIPE is unexpectedly ignored (see #8421 ), the system call returns error code EPIPE.

    Kevin Marquette (@KevinMarquette): Yes, as you say,Select-Object uses internal class StopUpstreamCommandsException to stop upstream cmdlets, and, as an aside, it would be nice for user code to have that ability too - see #3821 and #6070.

    In the case at hand, however, it would have to be PowerShell that does the SIGPIPE / EPIPE detection and translates it into PowerShell-appropriate termination of the upstream commands.

    I haven't looked into the implementation side of things yet.

  5. iSazonov commented on Dec 8, 2018

    @iSazonov
    Collaborator

    Thanks Michael Klement (@mklement0) - I did not read #8421 before commented here.

    For reference #2450

  6. changed the title [-]PowerShell commands run to completion even with a broken pipe to an external program on Unix-like platforms[/-] [+]PowerShell commands run to completion even with a broken pipe to an external (native) program[/+] on Nov 8, 2021
  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  10. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions