Merge pull request #8415 from heyitsanthony/fix-resolv-unix

netutil: don't resolve unix socket URLs when comparing URLs
This commit is contained in:
Anthony Romano 2017-08-18 13:24:34 -07:00 committed by GitHub
commit 2321835c47
2 changed files with 41 additions and 8 deletions

View File

@ -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)
}
}

View File

@ -92,7 +92,10 @@ 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) {
for ctx.Err() == nil { if u.Scheme == "unix" || u.Scheme == "unixs" {
// unix sockets don't resolve over TCP
return "", nil
}
host, _, err := net.SplitHostPort(u.Host) host, _, err := net.SplitHostPort(u.Host)
if err != nil { if err != nil {
plog.Errorf("could not parse url %s during tcp resolving", u.Host) plog.Errorf("could not parse url %s during tcp resolving", u.Host)
@ -101,6 +104,7 @@ func resolveURL(ctx context.Context, u url.URL) (string, error) {
if host == "localhost" || net.ParseIP(host) != nil { if host == "localhost" || net.ParseIP(host) != nil {
return "", nil return "", nil
} }
for ctx.Err() == 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())