Open
Description
What version of Go are you using (go version
)?
$ go version 1.17
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 GO111MODULE="on" GOARCH="amd64" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOPRIVATE="" GOPROXY="https://goproxy.cn,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.17.6" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jx/d_08_gm93psc4v9lm3zzjc300000gn/T/go-build1736071007=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
func test() {
client, err := ssh.Dial("tcp", "xx.xx.xx.xx:22", &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{ssh.Password("123")},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
})
if err != nil {
log.Panic(err)
}
session, err := client.NewSession()
if err != nil {
log.Panic(err)
}
defer session.Close()
go func() {
// err := session.Run("while true;do echo test;done")
err := session.Run("sleep 6000")
if err != nil {
log.Println(err)
}
}()
time.Sleep(time.Second * 5)
err = session.Close()
if err != nil {
log.Println(err)
}
log.Println("finished")
}
What did you expect to see?
2022/04/12 13:35:17 finished
2022/04/12 13:35:17 Process exited with status 141 from signal PIPE
What did you see instead?
2022/04/12 13:35:17 finished
If I run while true;do echo test;done
, the session can be closed gracefully. However sleep 6000
is still running after this process finished.