Set connect timeout

References: https://todo.sr.ht/~emersion/soju/26
This commit is contained in:
Simon Ser 2020-04-01 16:41:17 +02:00
parent 29f2e93ab7
commit bca0b2ad76
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 4 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import (
// TODO: make configurable
var keepAlivePeriod = time.Minute
var retryConnectMinDelay = time.Minute
var connectTimeout = 15 * time.Second
var writeTimeout = 10 * time.Second
func setKeepAlive(c net.Conn) error {

View File

@ -82,8 +82,10 @@ func connectToUpstream(network *network) (*upstreamConn, error) {
addr = addr + ":6697"
}
dialer := net.Dialer{Timeout: connectTimeout}
logger.Printf("connecting to TLS server at address %q", addr)
netConn, err := tls.Dial("tcp", addr, nil)
netConn, err := tls.DialWithDialer(&dialer, "tcp", addr, nil)
if err != nil {
return nil, fmt.Errorf("failed to dial %q: %v", addr, err)
}