all: Use context in lib/dialer (#6177)
* all: Use context in lib/dialer * a bit slimmer * https://github.com/syncthing/syncthing/pull/5753 * bot * missed adding debug.go * errors.Cause * simultaneous dialing * anti-leak
This commit is contained in:
committed by
Audrius Butkevicius
parent
4e151d380c
commit
1bae4b7f50
@@ -47,7 +47,7 @@ func newStaticClient(uri *url.URL, certs []tls.Certificate, invitations chan pro
|
||||
}
|
||||
|
||||
func (c *staticClient) serve(ctx context.Context) error {
|
||||
if err := c.connect(); err != nil {
|
||||
if err := c.connect(ctx); err != nil {
|
||||
l.Infof("Could not connect to relay %s: %s", c.uri, err)
|
||||
return err
|
||||
}
|
||||
@@ -146,13 +146,15 @@ func (c *staticClient) URI() *url.URL {
|
||||
return c.uri
|
||||
}
|
||||
|
||||
func (c *staticClient) connect() error {
|
||||
func (c *staticClient) connect(ctx context.Context) error {
|
||||
if c.uri.Scheme != "relay" {
|
||||
return fmt.Errorf("unsupported relay scheme: %v", c.uri.Scheme)
|
||||
}
|
||||
|
||||
t0 := time.Now()
|
||||
tcpConn, err := dialer.DialTimeout("tcp", c.uri.Host, c.connectTimeout)
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, time.Second)
|
||||
defer cancel()
|
||||
tcpConn, err := dialer.DialContext(timeoutCtx, "tcp", c.uri.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user