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: running command in session create not closed files #8306

Closed
gopherbot opened this issue Jul 1, 2014 · 2 comments
Closed

x/crypto/ssh: running command in session create not closed files #8306

gopherbot opened this issue Jul 1, 2014 · 2 comments
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 1, 2014

by acanthyostega:

What does 'go version' print?

** go version go1.3 linux/amd64

What steps reproduce the problem?

** Running the test case attached.

What happened?

** Trying to run a command through an ssh session create socket files (I think...) that
are not properly closed. When running such a program a large multiple number of times,
there is a big chance to reach the number of files opened imposed by the system (ulimit
-n). The evidence of such a creation can be accessed in /proc/${PID_OF_PROGRAM}/fd where
the number of file descriptors increase without stopping.

Reproducing all steps without calling session.Run(command) does not show this behaviour.

Since the documentation to use the ssh package is not very clear, I'm maybe missing
something...

What should have happened instead?

** A non increasing number of opened files when running multiple command with multiple
sessions.

** See the attached file for a test case (should work as it with go test...or not)

Thank you for any suggestion!

Attachments:

  1. mysession_test.go (2591 bytes)
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 1, 2014

Comment 1:

Labels changed: added repo-crypto, release-none.

@gopherbot gopherbot added new labels Jul 1, 2014
@bradfitz bradfitz removed the new label Dec 18, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc removed the release-none label Apr 10, 2015
@rsc rsc changed the title ssh: running command in session create not closed files x/crypto/ssh: running command in session create not closed files Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-crypto label Apr 14, 2015
@hanwen
Copy link
Contributor

@hanwen hanwen commented Aug 12, 2015

can't repro (go.crypto 2f3083f, go1.4.2).

test program:

package main

import (
"os"
"net"
"log"

"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"

)

func main() {
// Run a command for test
log.Println("pid ", os.Getpid())
for i := 0; i < 100; i++ {
log.Println("attempt ", i)
s := os.Getenv("SSH_AUTH_SOCK")
c, err := net.Dial("unix", s)
if err != nil { log.Fatal(err)}
a := agent.NewClient(c)
// Construct the configuration with password authentication
Config := &ssh.ClientConfig{
User: "hanwen",
Auth: []ssh.AuthMethod{ ssh.PublicKeysCallback(a.Signers) },
}

    Client, err := ssh.Dial(
        "tcp",
        "localhost:22",
        Config,
    )
    if err != nil {
        println("Can't connect to host!\n",
            "Reason is: ", err.Error())
    }

    // create session
    session, err := Client.NewSession()
    if err != nil {
        println(
            "Failed to create the session!\n",
            "Reason is :", err.Error(),
        )
    }

    // run a command
     err = session.Run("whoami")
     if err != nil {
     println("Failed to execute a command!\n",
     "Reason is: ", err.Error(),
     )
     }

    //close session
    session.Close()
    Client.Close()
}

}

@hanwen hanwen closed this Aug 18, 2015
@golang golang locked and limited conversation to collaborators Aug 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.