Skip to content

Commit

Permalink
transport_ssh: Check t is not nil before closing (#100)
Browse files Browse the repository at this point in the history
When connecting to a device where the user doesn't exist we get the
following:

```
goroutine 1 [running]:
github.com/Juniper/go-netconf/netconf.(*TransportSSH).Close(0x0, 0xc000108000, 0xc00009b040)
	/home/luke/work/src/github.com/Juniper/go-netconf/netconf/transport_ssh.go:42 +0x26
github.com/Juniper/go-netconf/netconf.DialSSHTimeout(0x62a7cb, 0x12, 0xc00009b040, 0x2540be400, 0x6325c1, 0x2f, 0xc00009b040)
	/home/luke/work/src/github.com/Juniper/go-netconf/netconf/transport_ssh.go:139 +0x110
main.main()
	/tmp/main.go:19 +0xc3
exit status 2
```

This is due to the connection being close without being established.

I have updated so we now get the following:

```
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
```
  • Loading branch information
luke-orden authored Oct 28, 2020
1 parent 9f37596 commit 6bda392
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion netconf/transport_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ func DialSSHTimeout(target string, config *ssh.ClientConfig, timeout time.Durati
conn := &deadlineConn{Conn: bareConn, timeout: timeout}
t, err := connToTransport(conn, config)
if err != nil {
t.Close()
if t != nil {
t.Close()
}
return nil, err
}

Expand Down

0 comments on commit 6bda392

Please sign in to comment.