Skip to content

Fix Invoke-Command missing error on session termination. #11586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 5, 2020
Merged

Fix Invoke-Command missing error on session termination. #11586

merged 4 commits into from
Feb 5, 2020

Conversation

PaulHigin
Copy link
Contributor

@PaulHigin PaulHigin commented Jan 15, 2020

PR Summary

This change fixes a problem in Invoke-Command against a remote session and that session is abruptly terminated, but no error is reported.

PR Context

In certain conditions, an abrupt session termination results in an Invoke-Command pipeline state going to 'Stopped' with an exception. Currently this is ignored in job processing because a user initiated stop is not an error. But a stopped state due to an error that is not 'PipelineStoppedException' (such as a remote transport exception) should not be ignored, but instead be treated as an error so that Invoke-Command will report it.

The fix is to update job error processing to correctly handle this error state.

Repro steps

$session = New-PSSession -cn vm1
Invoke-Command -Session $session -ScriptBlock { 1..1000 | % { sleep 1; "Output $_" } }

# Turn off virtual machine vm1

# Result
# No error is reported by Invoke-Command

# Expected
OpenError: [vm1] Processing data from remote server vm1 failed with the following error message: The request for the Windows Remote Shell with ShellId 8E31C82A-7B31-41F0-B882-E60EF7634D33 failed because the shell was not found on the server. Possible causes are: the specified ShellId is incorrect or the shell no longer exists on the server. Provide the correct ShellId or create a new shell and retry the operation. For more information, see the about_Remote_Troubleshooting Help topic.

PR Checklist

@ghost ghost assigned TravisEz13 Jan 15, 2020
@PaulHigin PaulHigin requested a review from SteveL-MSFT January 15, 2020 01:06
@PaulHigin PaulHigin added WG-Remoting PSRP issues with any transport layer Breaking-Change breaking change that may affect users Issue-Bug Issue has been identified as a bug in the product Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Jan 15, 2020
@PaulHigin
Copy link
Contributor Author

This is a possible breaking change. Some job ending states that used to be 'Stopped' with Exception, will now be 'Failed' with Exception. But I feel this is the correct behavior. The only time a 'Stopped' state is not an error is if there is no associated exception, or the exception is 'PipelineStopped'.

@PaulHigin
Copy link
Contributor Author

@PoshChan Please retry windows

@PoshChan
Copy link
Collaborator

@PaulHigin, successfully started retry of PowerShell-CI-Windows

Copy link
Collaborator

@JamesWTruher JamesWTruher left a comment

Choose a reason for hiding this comment

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

are there tests that can be added for this?

@PaulHigin
Copy link
Contributor Author

@JamesWTruher No, the repro is difficult to automate and still get the right error path. We don't need another fragile test.

@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Jan 15, 2020

@PowerShell/powershell-committee reviewed this and agree that the scenario where the pipeline is stopped with an error that is not a PipelineStoppedException it is a failure case, so this change is accepted.

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Jan 15, 2020
@PaulHigin
Copy link
Contributor Author

@TravisEz13 This change created a subtle regression. Please hold off merging until I have pushed the fix.

@PaulHigin
Copy link
Contributor Author

@SteveL-MSFT , @JamesWTruher Please re-review the changes. I have added a fix to the regression and also fixed the Stop-Job tests so that they will catch bad final state.

The regression was due to the pipeline returning a RemoteException exception on a pipeline stop instead of a PipelineStoppedException exception I was previously checking. A pipeline stopped RemoteException will contain an ErrorRecord with FQEID of 'PipelineStopped'.

The Stop-Job tests were not catching the incorrect final state because they ran before the job was actually running. Fix is to wait until job is running and returning data to the client.

@daxian-dbw daxian-dbw added this to the GA-consider milestone Jan 31, 2020
@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Jan 31, 2020
@PaulHigin
Copy link
Contributor Author

@SteveL-MSFT Please re-review.

@PaulHigin
Copy link
Contributor Author

@SteveL-MSFT ping...

@TravisEz13 TravisEz13 added the CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log label Feb 5, 2020
@TravisEz13 TravisEz13 changed the title Fix Invoke-Command missing error on session termination. Fix Invoke-Command missing error on session termination. Feb 5, 2020
@TravisEz13 TravisEz13 merged commit a5a97a5 into PowerShell:master Feb 5, 2020
@TravisEz13 TravisEz13 added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 5, 2020
@TravisEz13 TravisEz13 modified the milestones: GA-consider, GA-approved, 7.0.0 Feb 11, 2020
adityapatwardhan pushed a commit to adityapatwardhan/PowerShell that referenced this pull request Feb 18, 2020
@ghost
Copy link

ghost commented Feb 21, 2020

🎉v7.0.0-rc.3 has been released which incorporates this pull request.:tada:

Handy links:

@PaulHigin PaulHigin deleted the fix-missing-error-invokecommand branch February 24, 2020 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking-Change breaking change that may affect users CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision Issue-Bug Issue has been identified as a bug in the product WG-Remoting PSRP issues with any transport layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants