Skip to content

Commit

Permalink
use explicit timeout with context
Browse files Browse the repository at this point in the history
  • Loading branch information
HouseK committed Oct 11, 2023
1 parent 35b875b commit e37048c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ssh/tcpip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package ssh

import (
"context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -335,6 +336,9 @@ func (l *tcpListener) Addr() net.Addr {
// Dial initiates a connection to the addr from the remote host.
// The resulting connection has a zero LocalAddr() and RemoteAddr().
func (c *Client) Dial(n, addr string) (net.Conn, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var ch Channel
switch n {
case "tcp", "tcp4", "tcp6":
Expand All @@ -343,7 +347,7 @@ func (c *Client) Dial(n, addr string) (net.Conn, error) {
if err != nil {
return nil, err
}
port, err := net.LookupPort(n, portString)
port, err := net.DefaultResolver.LookupPort(ctx, n, portString)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e37048c

Please sign in to comment.