Skip to content

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

Open
unclejack wants to merge 1 commit into
contiv:masterfrom
unclejack:reuse_connection
Open

sshnode.go: use sessions & keep the client#25
unclejack wants to merge 1 commit into
contiv:masterfrom
unclejack:reuse_connection

Conversation

@unclejack

Copy link
Copy Markdown
Contributor

This PR is WIP.

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

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
Comment thread sshnode.go
n.client = client
}
if n.client == nil {
return fmt.Errorf("failed to connect to host")

Copy link
Copy Markdown
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

Comment thread sshnode.go
var s *ssh.Session
var err error

n.clientMutex.RLock()

@dseevr dseevr Jul 20, 2017

Copy link
Copy Markdown
Contributor

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?

Comment thread sshnode.go
if err != nil {
client.Close()
n.clientMutex.Lock()
n.client.Close()

Copy link
Copy Markdown
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