Skip to content

Commit

Permalink
Merge pull request #211 from foutrelis/fix-not-connected-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
czerwonk authored May 8, 2023
2 parents 511aa2b + 7bc46ce commit 727b229
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/connector/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ func (m *SSHConnectionManager) lockForDevice(device *Device) *sync.Mutex {
// Connect connects to a device or returns an long living connection
func (m *SSHConnectionManager) Connect(device *Device) (*SSHConnection, error) {
if connection, found := m.connections[device.Host]; found {
if !connection.isConnected() {
return nil, errors.New("not connected")
if connection.isConnected() {
return connection, nil
}

return connection, nil
}

mu := m.lockForDevice(device)
mu.Lock()
defer mu.Unlock()

if connection, found := m.connections[device.Host]; found {
return connection, nil
if connection.isConnected() {
return connection, nil
}
}

return m.connect(device)
Expand Down

0 comments on commit 727b229

Please sign in to comment.