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

proposal: os/exec,syscall: support running process on ConPty on Windows #62708

Open
aymanbagabas opened this issue Sep 18, 2023 · 8 comments · May be fixed by #62710
Open

proposal: os/exec,syscall: support running process on ConPty on Windows #62708

aymanbagabas opened this issue Sep 18, 2023 · 8 comments · May be fixed by #62710
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. OS-Windows Proposal
Milestone

Comments

@aymanbagabas
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.21.1 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Ayman\AppData\Local\go-build
set GOENV=C:\Users\Ayman\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Ayman\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Ayman\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Ayman\AppData\Local\Temp\go-build1093290718=/tmp/go-build -gno-record-gcc-switches

What did you do?

Windows now supports creating pseudo consoles, ConPty, using their Console API. As of now, we cannot run a process on a ConPty using os/exec. That's due to the fact that ConPty requires updating the process attributes with the Pty handle and pseudoconsole attribute (PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE = 0x00020016), and currently, there is no way to pass the Pty handle down to syscall.StartProcess.

See: https://learn.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session
Related: golang/sys#175

What did you expect to see?

The process runs on a ConPty session.

What did you see instead?

The process does not run on a ConPty session.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 18, 2023
@aymanbagabas aymanbagabas changed the title syscall: add SysProcAttr.PseudoConsole on Windows syscall(windows): running a process on a ConPty doesn't work Sep 18, 2023
@seankhliao
Copy link
Member

is there a specific change that you're proposing that could make it work?

cc @golang/windows

@seankhliao seankhliao changed the title syscall(windows): running a process on a ConPty doesn't work os/exec: support running process on ConPty Sep 18, 2023
@aymanbagabas
Copy link
Author

is there a specific change that you're proposing that could make it work?

cc @golang/windows

Yes, I just submitted #62710 to fix this issue

aymanbagabas added a commit to aymanbagabas/go that referenced this issue Sep 18, 2023
This allows the user to pass a ConPty handle to run a process on a
ConPty session.

See: https://learn.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session
Fixes: golang#62708
@bcmills bcmills changed the title os/exec: support running process on ConPty proposal: os/exec,syscall: support running process on ConPty Sep 19, 2023
@bcmills bcmills changed the title proposal: os/exec,syscall: support running process on ConPty proposal: os/exec,syscall: support running process on ConPty on Windows Sep 19, 2023
@gopherbot gopherbot added this to the Proposal milestone Sep 19, 2023
@bcmills bcmills moved this to Incoming in Proposals Sep 19, 2023
aymanbagabas added a commit to aymanbagabas/go that referenced this issue Sep 19, 2023
This allows the user to pass a ConPty handle to run a process on a
ConPty session.

See https://learn.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session
Fixes golang#62708
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/529315 mentions this issue: syscall: add SysProcAttr.PseudoConsole on Windows

@thanm thanm added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 25, 2023
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 25, 2023
@thanm thanm added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 25, 2023
@qmuntal
Copy link
Contributor

qmuntal commented Sep 26, 2023

This proposal doesn't contain the necessary API changes to support ConPty. For what I can see in the associated CL 529315, it would only need this addition into syscall.SysProcAttr :

type SysProcAttr struct {
        ...
	PseudoConsole              Handle              // if non-zero, the new process will be attached to the console represented by this handle, any AdditionalInheritedHandles will be ignored, this implies NoInheritHandles
}

Reading the docs and peeking at some code samples out there, adding this new property seems like enough to creating pseudoconsole sessions. What I can't find is documentation about why it precludes inheriting additional handles. Could you help me understanding that?

@aymanbagabas
Copy link
Author

aymanbagabas commented Sep 26, 2023

This proposal doesn't contain the necessary API changes to support ConPty. For what I can see in the associated CL 529315, it would only need this addition into syscall.SysProcAttr :

That's correct. This is where CL 528915 comes in place to add ConPty API to sys/windows. We need CL 529315 to support running processes on a ConPty.

Reading the docs and peeking at some code samples out there, adding this new property seems like enough to creating pseudoconsole sessions. What I can't find is documentation about why it precludes inheriting additional handles. Could you help me understanding that?

I couldn't find any info in the docs. All I found is this comment from hcsshim "If the client requested a pseudo console then there's nothing we need to do pipe wise, as the process inherits the other end of the pty's pipes."

EDIT: add node-pty and microsoft/node-pty#334 for reference

@qmuntal
Copy link
Contributor

qmuntal commented Sep 27, 2023

EDIT: add node-pty and microsoft/node-pty#334 for reference

Thanks for the sources. What I understood is that ConPty has a bug that makes it misbehave when inheriting handles. As it makes no sense to do that anyway, then handle inheriting is disabled. Looks fuzzy, but convinced me.

@aymanbagabas
Copy link
Author

Any updates on this one? #62710 CR 529315 only needs one addition to syscall.SysProcAttr to make spawning processes on a ConPty possible

type SysProcAttr struct {
        ...
	PseudoConsole              Handle              // if non-zero, the new process will be attached to the console represented by this handle, any AdditionalInheritedHandles will be ignored, this implies NoInheritHandles
}

CC/ @bcmills @thanm @qmuntal

@qmuntal
Copy link
Contributor

qmuntal commented Apr 8, 2024

Any updates on this one?

It still needs to complete the proposal process and get accepted. The next step is that this proposal is discussed by the proposals team, but it can take a while as the proposals queue is big.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. OS-Windows Proposal
Projects
Status: No status
Status: Incoming
Development

Successfully merging a pull request may close this issue.

6 participants