golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.41k stars 17.59k forks source link

A golang linux program spawned in WSL as a child process of a native Windows application does not exit #69845

Open iongion opened 2 hours ago

iongion commented 2 hours ago

Go version

go version go1.22.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/istoica/.cache/go-build'
GOENV='/home/istoica/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/istoica/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/istoica/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.22/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2861597373=/tmp/go-build -gno-record-gcc-switches'

What did you do?

  1. I create a windows native program - runs as a server
  2. I create a linux native program - runs a server
  3. I spawn the linux native program from the windows program, in a certain distribution using wsl.exe utility

What did you see happen?

When I close the native windows process, the child wsl does not exit.

What I notice is that wsl.exe launcher does some kind of forking, when it wraps and I see that the processes get detached from the main spawner. When I try to check if os.Getppid() process still exists in the linux binary, it is not able to find it.

On windows, the process tree looks like this after spawning, notice the windows process that launched the entire tree

image

Upon closing electron, the windows native process exits properly container-desktop-ssh-relay.exe

But what I see happening is that the processes under it, get detached and move to window's root process

image

The WSL linux golang program, is wrapped by wsl.exe at process 31112

image

What did you expect to see?

If the spawned program would be for example a native C based binary of /usr/sbin/sshd server (from openssh-server), started without running in the background, the exit process is proper and all the process tree gets killed.

I would expect the process tree to die properly.

gabyhelp commented 2 hours ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)