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

sshnode.go: use sessions & keep the client #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

unclejack
Copy link
Contributor

This PR is WIP.

This PR makes it possible to reuse a client connection and open multiple sessions. This saves time.

n.client = client
}
if n.client == nil {
return fmt.Errorf("failed to connect to host")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the err var above be put into the function scope so it can be part of this error message? That will help with debugging

var s *ssh.Session
var err error

n.clientMutex.RLock()
Copy link
Contributor

@dseevr dseevr Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do something like:

n.clientMutex.RLock()
client_ready := n.client != nil
n.clientMutex.RUnlock()

if !client_ready {
        n.clientMutex.Lock()
        n.connect()
        n.clientMutex.Unlock()
}

and get rid of the else branch and second n.clientMutex.RUnlock() call entirely?

if err != nil {
client.Close()
n.clientMutex.Lock()
n.client.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that every possible error returned from NewSession() requires a Close() and connect() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants