sshnode.go: use sessions & keep the client#25
Open
unclejack wants to merge 1 commit into
Open
Conversation
Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
dseevr
requested changes
Jul 20, 2017
| n.client = client | ||
| } | ||
| if n.client == nil { | ||
| return fmt.Errorf("failed to connect to host") |
Contributor
There was a problem hiding this comment.
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() |
Contributor
There was a problem hiding this comment.
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() |
Contributor
There was a problem hiding this comment.
Are we sure that every possible error returned from NewSession() requires a Close() and connect() ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is WIP.
This PR makes it possible to reuse a client connection and open multiple sessions. This saves time.