| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There is a race condition where `PipelineProcess.Stop()` can be called after `Dispose()` has already disposed the token. This causes the `Stop()` call to raise `ObjectDisposedException` crashing the process. An explicitly registered action on `$PSCmdlet.PipelineStopToken.Register()` can also throw an exception which is not handled in the stop call causing a similar crash. The fix is to ignore `AggregateException` which contains any exceptions raised by the user defined delegates on the stop token and exit early if the token has been disposed. We exit early because `Dispose()` has already done the work and there is nothing left to stop.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sorry, something went wrong.
There was a problem hiding this comment.
The tests do not reliably exercise cancellation of a disposed token source or the AggregateException handler, leaving the original crash without dependable regression coverage.
2 open issuesThis PR hardens pipeline cancellation to prevent shell crashes when stopping races with disposal or a registered stop-token callback throws, addressing #28299.
Changes:
| File | Description |
|---|---|
| test/powershell/Language/Scripting/PipelineStoppedToken.Tests.ps1 | Adds callback-failure coverage and moves readiness signals into test scripts. |
| src/System.Management.Automation/engine/pipeline.cs | Handles disposed cancellation sources and exceptions from stop-token callbacks. |
Review effort: Balanced
Sorry, something went wrong.
| { | ||
| _pipelineStopTokenSource.Cancel(); | ||
| } | ||
| catch (ObjectDisposedException) |
There was a problem hiding this comment.
Not sure how this would be possible without adding test only hooks that lock the state to a particular set of steps. This would be very complicated and means we start testing an implementation detail. Ultimately this is a race condition that I don't believe we can really test against.
Sorry, something went wrong.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
There is a race condition where PipelineProcess.Stop() can be called after Dispose() has already disposed the token. This causes the Stop() call to raise ObjectDisposedException crashing the process. An explicitly registered action on
$PSCmdlet.PipelineStopToken.Register() can also throw an exception which is not handled in the stop call causing a similar crash.
The fix is to ignore AggregateException which contains any exceptions raised by the user defined delegates on the stop token and exit early if the token has been disposed. We exit early because Dispose() has already done the work and there is nothing left to stop.
PR Context
Fixes: #28299
It also fixes a related problem where if the delegate registered by a caller could throw which is raised as an AggregateException. In C# this wouldn't typically happen but if someone in PowerShell provided any ScriptBlock delegate the cancellation will most likely be triggered somewhere that doesn't have a runspace. For example:
The fix is to ignore AggregateException so that this exception, any anything else a registered delegate a C# cmdlet would register, do not bring down the process.
This should be considered for backporting as well. While it is a race condition, the issue from #28299 shows that it can crash the whole process.
PR Checklist