Skip to content
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

Powershell hangs on startup #258

Closed
jpierson opened this issue Feb 22, 2016 · 30 comments
Closed

Powershell hangs on startup #258

jpierson opened this issue Feb 22, 2016 · 30 comments

Comments

@jpierson
Copy link

Just recently I installed Win32-OpenSSH using the new chocolatey package and I noticed that after rebooting I'm no longer able to start up PowerShell due to it hanging indefinitely. Not sure if this issue is an issue more with posh-git or Win32-OpenSSH but I thought I'd open some discussion.

Here is a starting place.
PowerShell/Win32-OpenSSH#42

@jpierson
Copy link
Author

Possibly related to #103

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 22, 2016

I assume commenting out the posh-git import in your $PROFILE (or starting PowerShell with -NoProfile) fixes the issue. What do you get from Get-Command ssh-* | select Path? Are you able to ssh-add in isolation (from PowerShell or cmd.exe)?

@jpierson
Copy link
Author

Actually I more surgically commented out the line Start-SshAgent -Quiet from profile.example.ps1 which then did allow me to get into PowerShell. Note that the fact that PowerShell ISE still worked was also a clue to where the problem was occurring.

Get-Command ssh-* | select Path

Path

C:\Program Files\OpenSSH-Win64\ssh-add.exe
C:\Program Files\OpenSSH-Win64\ssh-agent.exe
C:\Program Files\OpenSSH-Win64\ssh-keygen.exe
C:\Users\myuser\ManuallyInstalledApps\OpenSSH-Win32\ssh-keygen.exe
C:\Program Files\OpenSSH-Win64\ssh-keyscan.exe
C:\Program Files\OpenSSH-Win64\ssh-keysign.exe
C:\Program Files\OpenSSH-Win64\ssh-pkcs11-helper.exe

I was able to run ssh-add without a problem as well once I commented out the line mentioned above.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 23, 2016

So we have a problem in Start-SshAgent. Do you see anything if you run Start-SshAgent (no -Quiet) PowerShell loads? Are you able to run ssh-agent by itself?

@jpierson
Copy link
Author

Running Start-SshAgent seems to just hang after executing.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 24, 2016

Running Start-SshAgent seems to just hang after executing.

Can you tell where it's hanging? Are you able to run ssh-agent outside of Start-SshAgent?

@jpierson
Copy link
Author

I'm unfamialr with ssh-agent but I am able to run ssh-agent in PowerShell. It gives me output like the following.

set SSH_AUTH_SOCK=C:\Users\myname/.ssh/agent-7138.19688
set SSH_AGENT_PID=18736
echo Agent pid 18736;

Keep in mind that I have Posh-Git still enabled but the Start-SshAgent -Quiet line commented out still as mentioned above in order to get in to PowerShell.

@bazzilic
Copy link

I have experienced the same issue when I tried to install win32-openssh using Chocolatey yesterday. I am not sure though, was it the win32-openssh package issue or posh-git. I ended up uninstalling the package.

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 1, 2016

Well posh-git will use whatever ssh-agent it finds via PATH, and then attempts to guess where ssh-agent.exe might be located if it can't find it. Installing Win32-OpenSSH with Chocolatey will place it on PATH, so posh-git will use that.

My initial guess is that you're running into PowerShell/Win32-OpenSSH#110 at

& $sshAgent | foreach {

PowerShell/Win32-OpenSSH#35 is also related to ssh-agent, but does not seem related to this issue.

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 1, 2016

Found it: PowerShell/Win32-OpenSSH#110 (comment)

Until that can be fixed, we might want to add a warning here if the ssh-agent agent looks like it's from Win32-OpenSSH. 😦

@theaquamarine
Copy link
Collaborator

Latest Win32-OpenSSH release no longer includes ssh-agent and ssh-add.
https://github.com/PowerShell/Win32-OpenSSH/releases/tag/3_19_2016

@bazzilic
Copy link

Based on the release notes it looks like this is temporary.

@sixlettervariables
Copy link

I get intermittent hangs when PowerShell is used in a post-build script with Visual Studio 2015 with PoSH installed. Appears related to the SSH_AUTH_SOCK.env file being locked. Is this related to this issue?

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 31, 2016

I get intermittent hangs when PowerShell is used in a post-build script with Visual Studio 2015 with PoSH installed.

Try spawning PowerShell with -NoProfile.

Appears related to the SSH_AUTH_SOCK.env file being locked. Is this related to this issue?

Probably not? posh-git writes the .env files here as the agent processes complete (ultimately using Set-TempEnv). As far as I can tell, this bug prevents ssh-agent.exe from yielding any output that might result in setenv being called.

That being said, does your build hang only occur on machines with Win32-OpenSSH installed?

@sixlettervariables
Copy link

I'm currently the only dev with PoSH installed and yes I have Win32-OpenSSH, but the -NoProfile flag appears to help.

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 31, 2016

but the -NoProfile flag appears to help.

👍

@lzybkr
Copy link
Collaborator

lzybkr commented Mar 31, 2016

There is a bug in V3 and V4 of PowerShell that you might be hitting. If you load psreadline and some other module that generates an error into $error (older versions of posh-git definitely did, I'm not sure about newer), then you would occasionally hit a hang.

If this is the issue, you can check if PowerShell starts without a hang, immediately look at $error, if you have PSReadline and $error is not empty and you have V3/V4 PowerShell, this is likely the issue. The best fix is to avoid writing anything to $error, maybe requiring an update to posh-git. Another workaround is to call 'Get-Module -ListAvailable' in your profile - this can be slow, hence not really recommended.

@dahlbyk
Copy link
Owner

dahlbyk commented May 17, 2016

PowerShell/Win32-OpenSSH#110 (comment):

ssh-agent is reimplemented for Windows as a OS service. check out 5_15_2016 release details

@jkodroff
Copy link

@dahlbyk It appears to still be happening as of win32-openssh v2016.05.15. Maybe the ssh-agent as windows service thing is in the next release. Either way, it's not really a posh-git problem.

@dahlbyk
Copy link
Owner

dahlbyk commented Jun 15, 2016

If anyone were so inclined, we could suppress using ssh-agent if we can detect Win32-OpenSSH is installed. Or figure out a way to force using the one that ships with Git rather than the one on the path.

@dahlbyk
Copy link
Owner

dahlbyk commented Jun 17, 2016

From @DarwinJS on Chocolatey Gallery:

Installed the update to 0.6.1.20160330 to fix profile errors. Now when I launch powershell from anywhere, powershell opens, then a CMD opens. If I close the CMD, the powershell prompt never displays an actual input prompt - sits there like it's busy still booting up.

Do you happen to have Win32-OpenSSH installed? This seems like it could be related to [this issue].

In that package I do check if another sshd process / service is running and leave it alone if so.

What if you check if ssh-agent is already running before trying to start it?

Or is it possible to leave ssh activities up to the underlying git package? Let the user decide go on to properly configure git if they use keys?

There is a bigger issue here where SSH has been integrated into a lot of windows stuff - what to do if they then install win32-openssh?

I guess in theory win32-openssh would back down from being the primary on anything that is already installed in places it wants to go and it would issue warning messages?

Currently we default to whatever ssh-agent is found on PATH in Start-SshAgent. I wonder if we should skip that check and always use our Find-Ssh helper (which looks relative to the location of git.exe) instead?

@DarwinJS
Copy link

DarwinJS commented Jun 17, 2016

Currently we default to whatever ssh-agent is found on PATH in Start-SshAgent. I wonder if we should skip that check and always use our Find-Ssh helper (which looks relative to the location of git.exe) instead?

When Win32-OpenSSH is installed (and the user picked the option to install sshd), the ssh-agent is defined and started as a service. Unfortunately this means you have to get into system context to add keys - I do this with the scheduler and it can be seen in the code of the package.

What about looking for a running process called ssh-agent and just stand down if it is running?

Or better yet - pre-check if ssh-agent is running and which software on the system put it there? This would hopeful reveal the user's intent on which SSH they want to be primary on their system.

You can look in win32-openssh to see code patterns for figuring out the path of (and therefore which software package owns) a running sshd or ssh-agent. Win32-OpenSSH package only installs or upgrades or starts/stops ssh-agent or sshd IF the instance running is from it's own folder structure.

@dahlbyk
Copy link
Owner

dahlbyk commented Jun 20, 2016

What about looking for a running process called ssh-agent and just stand down if it is running?

Or better yet - pre-check if ssh-agent is running and which software on the system put it there?

We try to do this already in Start-SshAgent using a Get-SshAgent function that already works for MSYS ssh and plink. I would expect adapting these to also check for Win32-OpenSSH would be relatively simple.

@DarwinJS
Copy link

OK - here are the official install instructions: https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH

I just realized my package is not compliant with them because they didn't previously specify the application folder - so I think I put the binaries in "C:\Program Files" under the same subfolder that is in the zip. Which is "OpenSSH-Win32" and "OpenSSH-Win64" respectively.

I will work on aligning the folder name on the next package revision.

@theaquamarine
Copy link
Collaborator

Does Win32-OpenSSH actually work with git? I've never been able to make operations perform correctly and PowerShell/Win32-OpenSSH#247 suggests it's not just me. If it doesn't, I'd be inclined to say that we want to special case Win32-OpenSSH to avoid using it.

Equally, if/when git and Win32-OpenSSH do play well together, will git actually use the Win32-OpenSSH ssh.exe if it's first in the path, or will it use its own? If it prefers to use its own, I feel like we should also prefer to use the one provided with git, since the whole point of posh-git is to work with git.

@DarwinJS
Copy link

DarwinJS commented Jun 21, 2016

Win32-openssh probably has a ways to go to take up git responsibilities - but even then, who would want to do all that reconfig?

One challenge is that the ssh that comes with git is not actually used unless the individual sets the machine up to do so.

So maybe win32-openssh should look for a running instance of either ssh-agent or sshd that is not it's own - and if found, requires a special switch to forcibly install either of these on a system with it already configured?

It won't handle the reverse install order (win32-openssh installed first then git) - but it could be a good first step.

Maybe the same with the path if it finds a reference to ssh on it?

@dahlbyk
Copy link
Owner

dahlbyk commented Jun 30, 2016

Is anyone using Win32-OpenSSH able to take #295 for a spin to make sure it works as expected for you?

@rkeithhill
Copy link
Collaborator

@lzybkr

generates an error into $error

We are trying to avoid this but it is kind of a PITA. When we execute git.exe and it writes to stderr, we want to avoid users seeing that error text so we redirect - 2>$null. Unfortunately that causes the stderr output to be written to $Error.

We have code now that checks the $Error.Count and removes new errors. That kind of breaks down if $Error has hit its maximum count. Is there a better way to A) prevent users from seeing stderr and B) not writing stderr to $Error when executing a native command?

@dahlbyk
Copy link
Owner

dahlbyk commented Jun 18, 2018

This should be resolved by #586 in an upcoming v0.8 release.

@dahlbyk dahlbyk modified the milestones: SSH Agents, v0.8.0 Jun 18, 2018
@dahlbyk
Copy link
Owner

dahlbyk commented Mar 14, 2020

I believe this is adequately addressed by posh-sshell

@dahlbyk dahlbyk closed this as completed Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants