question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PowerShell hangs when exiting having used a PowerShell runspace pool/runspace

See original GitHub issue

PowerShell Core hangs when exiting and using a PowerShell runspace pool. On Windows PowerShell it exits successfully.

Steps to reproduce

here’s the gist for my code: https://gist.github.com/tylerl0706/2d87a13c6147278bb4e8565585aa9722

Steps:

PS > Add-Type -Path "path/to/TestHttpListener/bin/Debug/netstandard2.0/TestHttpListener.dll"
PS > $app = [TestHttpListener.TestHttpListener]::new()
PS > $app.Start(8081)
PS > Invoke-WebRequest -Uri http://localhost:8081 # VERY IMPORTANT
PS > exit

Expected behavior

PowerShell successfully exists

Actual behavior

PowerShell hangs and doesn’t give the prompt back - this is causing my AppVeyor and Travis builds to fail due to timeout 😦

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.8
PSEdition                      Core
GitCommitId                    v6.0.0-beta.8
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
PaulHigincommented, Nov 3, 2017

@anmenaga, We really need to be able to depend on the CLR to work as advertised. We have other places in the code that relies on the finalizer to work. I’ll investigate more and if this looks like a CLR regression I’ll notify the team.

But for the short term I’ll create a workaround to fix this particular hang problem for RC using our existing cleanup on exit code.

2reactions
SteveL-MSFTcommented, Oct 25, 2017

I think I have a simpler repro without using httplistener

PS /Users/steve> $rs = [runspacefactory]::CreateRunspacePool(1,5)                                                                                               
PS /Users/steve> $rs.Open()                                                                                                                                     
PS /Users/steve> $ps = [powershell]::Create()                                                                                                                   
PS /Users/steve> $ps.RunspacePool = $rs                                                                                                                         
PS /Users/steve> $null = $ps.AddScript({1+1})                                                                                                                           
PS /Users/steve> $ps.Invoke()
PS /Users/steve> exit #hangs            
Read more comments on GitHub >

github_iconTop Results From Across the Web

WPF runspace crashes using powershell version 2
So I create two runspaces, one that creates and shows the WPF gui and the other one executes my install script. That works...
Read more >
Exit foreground script Powershell: script hangs and Ctrl+C ...
It connects, reads the stream, writes to file, but does not exit. I then try to use Ctrl+C and it does not work....
Read more >
Why does PsExec hang after successfully running a ...
No matter what I do, it hangs until I the locally on the cmd prompt. After I hit enter, I get the message:...
Read more >
PowerShell script not exiting after completion
I have a question: I am using PowerShell to install Bentley ProjectWise Explorer via MDT. It works perfectly when run via a batch...
Read more >
PowerShell 64-bit hanging on new machine
PowerShell 5.1.17763.316 and PowerShell Core 6.1.1; I have plenty of memory left (>16GB) and CPU is near idle while it's hanging. Only Windows ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found