Skip to content

Commit

Permalink
Fix "Could not connect to x: not connected" errors
Browse files Browse the repository at this point in the history
Tweak SSHConnectionManager.Connect() to return a new connection if the
previous one is not connected. (This occurs with expired connections.)

Maybe fixes: #56
  • Loading branch information
foutrelis committed May 2, 2023
1 parent 511aa2b commit 7bc46ce
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 7bc46ce

Please sign in to comment.