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

x/crypto: ssh.NewChannel from ssh.NewServerConn() returns nil values #57560

Closed
benschlueter opened this issue Jan 3, 2023 · 1 comment
Closed

Comments

@benschlueter
Copy link

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

go version go1.19.4 linux/amd64

Does this issue reproduce with the latest release?

yes

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

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

What did you do?

func (s *sshRelay) handleChannels(ctx context.Context, chans <-chan ssh.NewChannel) {
	// Service the incoming Channel channel in go routine
	handleChannelWg := &sync.WaitGroup{}
	defer handleChannelWg.Wait()
	for {
		select {
		case <-ctx.Done():
			return
		case newChannel := <-chans:
			if newChannel == nil {
				s.log.Info("nil value from channel")
				continue
			}
			handleChannelWg.Add(1)
			go s.handleChannel(ctx, handleChannelWg, newChannel)
		}
	}
}

What did you expect to see?

chan should not return nil values. The example in crypto/ssh/example_test also does not check for nil

What did you see instead?

Even if the ssh session is closed from the client side, the channel is still served with nil's

Not sure if I consume something wrong and the garbage collector is supposed to cleanup the channel, but if I terminate the client ssh session the log looks like the following:

{"level":"info","msg":"nil value from channel"}
{"level":"info","msg":"nil value from channel"}
{"level":"info","msg":"nil value from channel"}
{"level":"info","msg":"nil value from channel"}
....
{"level":"info","msg":"nil value from channel"}
{"level":"info","msg":"nil value from channel"}
@gopherbot gopherbot added this to the Unreleased milestone Jan 3, 2023
@seankhliao
Copy link
Member

https://go.dev/ref/spec#Receive_operator

A receive operation on a closed channel can always proceed immediately, yielding the element type's zero value after any previously sent values have been received.

The example ends on channel close.
I believe this is working as intended.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2023
@golang golang locked and limited conversation to collaborators Jan 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants