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

SSH hang when running ssh with std_handles redirected on Win10 #1330

Closed
anrose00 opened this issue Jan 24, 2019 · 4 comments
Closed

SSH hang when running ssh with std_handles redirected on Win10 #1330

anrose00 opened this issue Jan 24, 2019 · 4 comments

Comments

@anrose00
Copy link

anrose00 commented Jan 24, 2019

Please answer the following

"OpenSSH for Windows" version
((Get-Item (Get-Command sshd).Source).VersionInfo.FileVersion) => 7.9.0.0

Server OperatingSystem
Linux 4.4.91 #1-NixOS SMP x86_64 GNU/Linux
also tested with "sshd" on Windows Srv 2016

sshd version:
Remote protocol version 2.0, remote software version OpenSSH_7.6

Client OperatingSystem
Windows 10 Pro - 1709 - Build 16299.785

What is failing
ssh.exe hangs when executing remote commands and std_handles are being redirected.

Example:

ssh -n -T user@server ls < NUL > stdout.txt 2> stderr.txt

Expected behavior
Command should be executed and the output of "ls" should be written to stdout.txt. ssh should terminate after execution.

Actual behavior
Command gets executed and the output of "ls" is being written to stdout.txt. ssh DOES NOT terminate after execution (hangs). If you kill the command process and inspect stdout.txt the expected output is there. So the remote command did complete.

The same command works without problems on Win7

@manojampalam
Copy link
Contributor

manojampalam commented Jan 24, 2019

Underlying issue is the same discussed in #856.

The IO on /dev/null (specified via -n) is somehow getting hung when NUL is explicitly redirected.
Following would still work

ssh -n -T user@server ls > stdout.txt 2> stderr.txt

I've put a workaround for the issue and you should have it in next release.
Private: ssh.zip

@anrose00
Copy link
Author

Big thanks for the quick response!

manojampalam added a commit to PowerShell/openssh-portable that referenced this issue May 21, 2019
PowerShell/Win32-OpenSSH#1330

Issue: open(dev/nul) returns a handle is passes isatty() test (i.e its being treated as a terminal handle by OS). This handle seems to work fine for as a console handle for console APIs, except when NUL is explicitly redirected. 
This works
ssh -n target hostname

but this hangs due to a deadlock from writing a log entry on a console API failure
ssh -n target hostname < NUL

Fix: Ignore console API failures when the handle is being reported as invalid.
@manojampalam manojampalam modified the milestones: vNext, v8.0.0.0p1-Beta Jun 23, 2019
@petr-motejlek
Copy link

petr-motejlek commented Nov 7, 2020

Somehow, this still seems to be a problem with OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5 (which got installed by Windows for me).

When I run a command like ssh user@server -- cat /etc/motd < NUL, I get the proper output on stdout, but then the process just hangs, never quits.

I found this out after searching heavily after not being able to perform a git lfs fetch, because it was hanging. Eventually, I figured it was because it is running a similar ssh command to get some output from the server. Well, it gets the output, bu ssh's stdout never closes, so it just sits there. There's this weird GetConsoleMode on STD_INPUT_HANDLE failed with 6 message printed also.

Is there a more recent version I could install on my Windows 10 machine?

@anrose00
Copy link
Author

Is there a more recent version I could install on my Windows 10 machine?

See: https://github.com/PowerShell/Win32-OpenSSH/releases

Unfortunately Microsoft is still installing the 7.7p1 version even with current Win10 versions, although newer ssh versions have been released and a lot of bugs have been fixed in the mean time.

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

3 participants