mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #8415 from heyitsanthony/fix-resolv-unix
netutil: don't resolve unix socket URLs when comparing URLs
This commit is contained in:
commit
2321835c47
@ -84,3 +84,32 @@ func TestEtcdMultiPeer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestEtcdUnixPeers checks that etcd will boot with unix socket peers.
|
||||||
|
func TestEtcdUnixPeers(t *testing.T) {
|
||||||
|
d, err := ioutil.TempDir("", "e1.etcd")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(d)
|
||||||
|
proc, err := spawnCmd(
|
||||||
|
[]string{
|
||||||
|
binDir + "/etcd",
|
||||||
|
"--data-dir", d,
|
||||||
|
"--name", "e1",
|
||||||
|
"--listen-peer-urls", "unix://etcd.unix:1",
|
||||||
|
"--initial-advertise-peer-urls", "unix://etcd.unix:1",
|
||||||
|
"--initial-cluster", "e1=unix://etcd.unix:1",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
defer os.Remove("etcd.unix:1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err = waitReadyExpectProc(proc, etcdServerReadyLines); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err = proc.Stop(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -92,15 +92,19 @@ func resolveTCPAddrs(ctx context.Context, urls [][]url.URL) ([][]url.URL, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveURL(ctx context.Context, u url.URL) (string, error) {
|
func resolveURL(ctx context.Context, u url.URL) (string, error) {
|
||||||
|
if u.Scheme == "unix" || u.Scheme == "unixs" {
|
||||||
|
// unix sockets don't resolve over TCP
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
host, _, err := net.SplitHostPort(u.Host)
|
||||||
|
if err != nil {
|
||||||
|
plog.Errorf("could not parse url %s during tcp resolving", u.Host)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if host == "localhost" || net.ParseIP(host) != nil {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
for ctx.Err() == nil {
|
for ctx.Err() == nil {
|
||||||
host, _, err := net.SplitHostPort(u.Host)
|
|
||||||
if err != nil {
|
|
||||||
plog.Errorf("could not parse url %s during tcp resolving", u.Host)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if host == "localhost" || net.ParseIP(host) != nil {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
tcpAddr, err := resolveTCPAddr(ctx, u.Host)
|
tcpAddr, err := resolveTCPAddr(ctx, u.Host)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
plog.Infof("resolving %s to %s", u.Host, tcpAddr.String())
|
plog.Infof("resolving %s to %s", u.Host, tcpAddr.String())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user