Coder Social home page Coder Social logo

powershellasync's People

Contributors

pgrefviau avatar tig avatar tjrockefeller avatar ttrider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

powershellasync's Issues

Exceptions thrown in async methods get lost

Thank you for this great little library. It seems to work well apart from the fact that any exceptions that my cmdlets throw simply disappear. I propose that the behavior should be as close as possible to exceptions in synchronous cmdlets, i.e. exceptions should stop the pipeline and get printed out on the console.

Exceptions thrown in async code get wrapped in an AggregateException which is not very useful when printed on the console. Ideally, your library would unwrap these before rethrowing them, at least for the common case when there's only one inner exception.

Calls like ShouldContinue and WriteProgress deadlock after await

If I do this:

 var path = await ServiceLocator.Current.UpdateService.StartUpgradeAsync();
 ShouldContinue("my message.", "Exit this Powershell instance?");

The deadlock happens here:

this.retValTask.Wait();

However, if I do this:

 var path = await ServiceLocator.Current.UpdateService.StartUpgradeAsync();
 await Task.Run(() => ShouldContinue("my message.", "Exit this Powershell instance?"));

That Wait doesn't block, but instead the task gets pulled off the queue and invoked via the below as expected.

var waitable = task.ContinueWith(t => synchronizationContext.Complete(), scheduler: TaskScheduler.Default);

I think there's probably something that could be done to how methods like ShouldContinue are wrapped by PowerShellAsync to fix this:

public new bool ShouldContinue(string query, string caption)

For now, I'm moving forward by just wrapping CmdLet calls like ShouldContinue and WriteProgress which appear to not be correctlyl wrapped by PowerShellAsync with Task.Run calls. I don't grok this stuff well enough yet to propose a specific fix. I suspect it's very similar/related to #2.

See also: PowerShell/PowerShell#7690

Task continuations do not resume on main "Pipeline Execution" thread

I ran into exceptions thrown by System.Management.Automation methods when trying to invoke script snippets from within the ProcessRecordAsync override of an AsyncCmdlet. More specifically, the exception originated from the System.Management.Automation.ScriptBlock.GetContextFromTLS() method. LocalPipeline.GetExecutionContextFromTLS() would always return null for some reason.

After some investigation, I realized that that, earlier in my Cmdlet's control flow, an async call was made whose continuation did not marshall back to the initial thread (appropriately called "Pipeline Execution Thread"), which led to the "CommandInvokedFromWrongThread" error.

The AsyncCmdlet logic should ensure that the tasks awaited from within the various 'async' method overload it exposes are marshalled back to that main thread specifically to avoid running into those issues.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.