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: session remains open if Close is called without sending data #31401
Comments
How? (If you're having a problem with a specific package, please provide specific steps that we can follow exactly to reproduce the problem with that package.) |
@bcmills ,ok,like this: import (
"golang.org/x/crypto/ssh"
"time"
"net"
"fmt"
)
func main() {
sess, err := Sshconnect("xxx", "xxx", "170.0.44.1", 22, 10)
fmt.Println("open :", err)
err = sess.Run("pwd")
fmt.Println("run :", err)
err = sess.Close()
fmt.Println("close :", err)
time.Sleep(time.Minute)
}
func Sshconnect(user, password, host string, port int, timeout int) (*ssh.Session, error) {
var (
auth []ssh.AuthMethod
addr string
clientConfig *ssh.ClientConfig
client *ssh.Client
session *ssh.Session
err error
)
auth = make([]ssh.AuthMethod, 0)
auth = append(auth, ssh.Password(password))
clientConfig = &ssh.ClientConfig{
User: user,
Auth: auth,
Timeout: time.Duration(timeout) * time.Second,
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
// connet to ssh
addr = fmt.Sprintf("%s:%d", host, port)
if client, err = ssh.Dial("tcp", addr, clientConfig); err != nil {
return nil, err
}
// create session
if session, err = client.NewSession(); err != nil {
return nil, err
}
return session, nil
} |
I think that this is probably not a bug, but is tangentially related to #32453 etc. The error is returned because the session has already been closed (by (As an aside, this seems to be a subtle API to use correctly. The session can be closed asynchronously at any time by the other side, and so it's always possible for correctly-written code to get an For reference, turning on the
|
@wiml yes,you are right. I tried to close the client not session, and there is no connection leak.Thank you for your reply! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I create a new ssh client,dial and run is ok,but when i close the client i got the EOF error.
I set the debugMux is true to log the ssh detail and found that the server always send the
msgChannelClose
msg after the commond is successly run.But the client only set
sentClose
true,not do anything.So when i call the close method it result an EOF error,but the client didnot send close msg to the server.And use the linux commondthe ssh connection is still alive. It results after a long time ,my process cannot open any file because of "too many files".
I tried to notes the code
if ch.sentClose { ch.writeMu.Unlock() return io.EOF }
,and it can work.What did you expect to see?
Is that a bug?
What did you see instead?
The text was updated successfully, but these errors were encountered: