Skip to content

Commit

Permalink
Merge pull request scylladb#378 from Zariel/tls-dial-timeout
Browse files Browse the repository at this point in the history
Use timeouts when dialing tls sockets
  • Loading branch information
Zariel committed Apr 26, 2015
2 parents 0812843 + b64d286 commit f7394ea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,19 @@ func Connect(addr string, cfg ConnConfig, errorHandler ConnErrorHandler) (*Conn,
conn net.Conn
)

dialer := &net.Dialer{
Timeout: cfg.Timeout,
}

if cfg.tlsConfig != nil {
// the TLS config is safe to be reused by connections but it must not
// be modified after being used.
if conn, err = tls.Dial("tcp", addr, cfg.tlsConfig); err != nil {
return nil, err
}
} else if conn, err = net.DialTimeout("tcp", addr, cfg.Timeout); err != nil {
conn, err = tls.DialWithDialer(dialer, "tcp", addr, cfg.tlsConfig)
} else {
conn, err = dialer.Dial("tcp", addr)
}

if err != nil {
return nil, err
}

Expand Down

0 comments on commit f7394ea

Please sign in to comment.