Add default timeout to instantiate connection
This commit is contained in:
parent
0aeb8660a7
commit
b85cf1edcc
12
ftp.go
12
ftp.go
@ -18,6 +18,12 @@ import (
|
||||
"github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
const (
|
||||
// 30 seconds was chosen as it's the
|
||||
// same duration as http.DefaultTransport's timeout.
|
||||
DefaultDialTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
// EntryType describes the different types of an Entry.
|
||||
type EntryType int
|
||||
|
||||
@ -115,6 +121,12 @@ func Dial(addr string, options ...DialOption) (*ServerConn, error) {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(ctx, DefaultDialTimeout)
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
if do.tlsConfig != nil && !do.explicitTLS {
|
||||
dialFunc = func(network, address string) (net.Conn, error) {
|
||||
tlsDialer := &tls.Dialer{
|
||||
|
Loading…
Reference in New Issue
Block a user