Skip to content

Select-String breaks when used with ForEach-Object -Parallel and Start-ThreadJob #11242

@mklement0

Description

@mklement0

@jszabo98 discovered the Start-ThreadJob problem in #11092; it affects ForEach-Object -Parallel as well

Unlike #11092, it doesn't seem to be related to output formatting data per se, but to the VT escape sequences created to highlight the matching part of a line, given that the problem goes away when you add -NoEmphasis - even though the tests use -Raw for direct [string] output, in which case -NoEmphasis should have no effect, given that -Raw doesn't perform highlighting.

Steps to reproduce

# Adding -NoEmphasis to Select-String makes the problem go away.
Start-ThreadJob { 'hi' | Select-String hi -Raw } | Receive-Job -Wait -AutoRemoveJob | Should -be hi
'hi' | ForEach-Object -parallel { $_ | Select-String hi -Raw } | Should -Be hi

Expected behavior

Both tests should pass.

Actual behavior

Both tests emit an error message and fail:

Select-String: Object reference not set to an instance of an object.
...
 ^ Expected 'hi', but got $null.

Environment data

PowerShell Core 7.0.0-preview.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-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