transport/local: hard fail, more aggressive connect timeout

This commit is contained in:
Christian Schwarz 2019-09-09 22:15:18 +02:00
parent 7ba3ae077f
commit 2cd9173bfb

View File

@ -3,6 +3,7 @@ package local
import (
"context"
"fmt"
"time"
"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/transport"
@ -25,5 +26,11 @@ func LocalConnecterFromConfig(in *config.LocalConnect) (*LocalConnecter, error)
func (c *LocalConnecter) Connect(dialCtx context.Context) (transport.Wire, error) {
l := GetLocalListener(c.listenerName)
return l.Connect(dialCtx, c.clientIdentity)
dialCtx, cancel := context.WithTimeout(dialCtx, 1*time.Second) // fail fast, config error by user is very likely
defer cancel()
w, err := l.Connect(dialCtx, c.clientIdentity)
if err == context.DeadlineExceeded {
return nil, fmt.Errorf("local listener %q not reachable", c.listenerName)
}
return w, err
}