Skip to content

Add an environement variable to control stdio mode#759

Merged
tgauth merged 2 commits into
PowerShell:latestw_allfrom
manu0401:socket_stdio
Nov 19, 2024
Merged

Add an environement variable to control stdio mode#759
tgauth merged 2 commits into
PowerShell:latestw_allfrom
manu0401:socket_stdio

Conversation

@manu0401

Copy link
Copy Markdown

stdio descriptors (stdin, stdout and stderr) can be operated in various modes by win32compat code. The behavior is set very early in fd_table_initialize() by setting pio->type.

In PowerShell/Win32-OpenSSH#1427 it was chosen to set pio->type to NONSOCK_SYNC_FD to resolve an I/O hang problem. Unfortunately this introduce problems for other ssh usage.

sshfs-wiun uses ssh and has at leas 6 open issues for the same problem introduced by this NONSOCK_SYNC_FD change: https://github.com/winfsp/sshfs-win/issues?q=is%3Aissue+cb+%3A87

The sshfs-win workaround it to use an older ssh.exe from cygwin, which is bundled with sshfs-win. This program is unable to use ssh-agent, which is quite frustrating. And if PATH is not set to use it, sshfs-win cannot work.

This change introduce an OPENSSH_STDIO_MODE environment variable that can be set to the following values: unknown, sock, nonsock, nonsock_sync. It cause pio->type to be set to UNKNOWN_FD, SOCK_FD, NONSOCK_FD, and NONSOCK_SYNC_FD respecitively. The default behavior when the variable is not set is unchanged (which means NONSOCK_SYNC_FD).

Setting OPENSSH_STDIO_MODE="nonsock" lets sshfs-win work again with openssh-portable ssh.exe. ssh-agent can be used, and this is good.

PR Summary

PR Context

stdio descriptors (stdin, stdout and stderr) can be operated in various
modes by win32compat code. The behavior is set very early in
fd_table_initialize() by setting pio->type.

In PowerShell/Win32-OpenSSH#1427 it was
chosen to set pio->type to NONSOCK_SYNC_FD to resolve an I/O hang
problem. Unfortunately this introduce problems for other ssh usage.

sshfs-wiun uses ssh and has at leas 6 open issues for the same
problem introduced by this NONSOCK_SYNC_FD change:
https://github.com/winfsp/sshfs-win/issues?q=is%3Aissue+cb+%3A87

The sshfs-win workaround it to use an older ssh.exe from cygwin, which
is bundled with sshfs-win. This program is unable to use ssh-agent,
which is quite frustrating. And if PATH is not set to use it, sshfs-win
cannot work.

This change introduce an OPENSSH_STDIO_MODE environment variable that
can be set to the following values: unknown, sock, nonsock, nonsock_sync.
It cause pio->type to be set to UNKNOWN_FD, SOCK_FD, NONSOCK_FD, and
NONSOCK_SYNC_FD respecitively. The default behavior when the variable
is not set is unchanged (which means NONSOCK_SYNC_FD).

Setting OPENSSH_STDIO_MODE="nonsock" lets sshfs-win work again with
openssh-portable ssh.exe. ssh-agent can be used, and this is good.
@manu0401

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@tgauth

tgauth commented Nov 7, 2024

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread contrib/win32/win32compat/w32fd.c Outdated
An assert(pio->type != UNKNOWN_FD) in fd_table_set() causes that
case to fail early anyway.
@manu0401 manu0401 requested review from tgauth November 14, 2024 00:44
@manu0401

Copy link
Copy Markdown
Author

The change is approved, thank you, but what is now preventing it from being merged?

@innodonni

Copy link
Copy Markdown

I am facing issues with ssh reliability even having tweaked the client and server keepalive options. As a workaround, I want to read a remote process ID before subsequent lines of output but I am facing buffering until the remote process has exited. I have a feeling this is a common requirement among devs who want POSIX pty-like line-buffering but get standard libc buffering when the output is a pipe. Will this functionality allow me to essentially setvbuf to unbuffer the ssh output I am receiving with C# Process API?

@tgauth tgauth merged commit 27f6cfa into PowerShell:latestw_all Nov 19, 2024
manu0401 added a commit to manu0401/sshfs that referenced this pull request Nov 20, 2024
Windows native OpenSSH has alternative behavior for standard I/O
descriptors, which can be selected through the OPENSSH_STDIO_MODE
environement variable. Setting it to "nonsock" is required for
sshfs compatibility.

See PowerShell/openssh-portable#759
for details.
manu0401 added a commit to manu0401/sshfs-win that referenced this pull request Nov 20, 2024
Windows native OpenSSH has alternative behavior for standard I/O
descriptors, which can be selected through the OPENSSH_STDIO_MODE
environement variable. Setting it to "nonsock" is required for
sshfs compatibility.

See PowerShell/openssh-portable#759
for details.

Subitted upstream here
libfuse/sshfs#314
hazelduvall pushed a commit to hazelduvall/openssh-portable that referenced this pull request May 6, 2026
* Add an environement variable to control stdio mode

stdio descriptors (stdin, stdout and stderr) can be operated in various
modes by win32compat code. The behavior is set very early in
fd_table_initialize() by setting pio->type.

In PowerShell/Win32-OpenSSH#1427 it was
chosen to set pio->type to NONSOCK_SYNC_FD to resolve an I/O hang
problem. Unfortunately this introduce problems for other ssh usage.

sshfs-wiun uses ssh and has at leas 6 open issues for the same
problem introduced by this NONSOCK_SYNC_FD change:
https://github.com/winfsp/sshfs-win/issues?q=is%3Aissue+cb+%3A87

The sshfs-win workaround it to use an older ssh.exe from cygwin, which
is bundled with sshfs-win. This program is unable to use ssh-agent,
which is quite frustrating. And if PATH is not set to use it, sshfs-win
cannot work.

This change introduce an OPENSSH_STDIO_MODE environment variable that
can be set to the following values: unknown, sock, nonsock, nonsock_sync.
It cause pio->type to be set to UNKNOWN_FD, SOCK_FD, NONSOCK_FD, and
NONSOCK_SYNC_FD respecitively. The default behavior when the variable
is not set is unchanged (which means NONSOCK_SYNC_FD).

Setting OPENSSH_STDIO_MODE="nonsock" lets sshfs-win work again with
openssh-portable ssh.exe. ssh-agent can be used, and this is good.

* Leave out  UNKNOWN_FD as the possible rtpes for stdio descriptors

An assert(pio->type != UNKNOWN_FD) in fd_table_set() causes that
case to fail early anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants