Skip to content

Commit

Permalink
embed: connect json gateway with user-provided listen address
Browse files Browse the repository at this point in the history
net.Listener says its address is [::] when given 0.0.0.0, breaking
hosts that have ipv6 disabled.

Fixes etcd-io#8151
Fixes etcd-io#7961
  • Loading branch information
heyitsanthony authored and Iwasaki Yudai committed Oct 5, 2017
1 parent 1a7d7b5 commit d01a8bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions embed/etcd.go
Expand Up @@ -328,6 +328,9 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
if sctx.l, err = net.Listen(proto, addr); err != nil {
return nil, err
}
// net.Listener will rewrite ipv4 0.0.0.0 to ipv6 [::], breaking
// hosts that disable ipv6. So, use the address given by the user.
sctx.addr = addr

if fdLimit, fderr := runtimeutil.FDLimit(); fderr == nil {
if fdLimit <= reservedInternalFDNum {
Expand Down
3 changes: 2 additions & 1 deletion embed/serve.go
Expand Up @@ -44,6 +44,7 @@ import (

type serveCtx struct {
l net.Listener
addr string
secure bool
insecure bool

Expand Down Expand Up @@ -171,7 +172,7 @@ type registerHandlerFunc func(context.Context, *gw.ServeMux, *grpc.ClientConn) e

func (sctx *serveCtx) registerGateway(opts []grpc.DialOption) (*gw.ServeMux, error) {
ctx := sctx.ctx
conn, err := grpc.DialContext(ctx, sctx.l.Addr().String(), opts...)
conn, err := grpc.DialContext(ctx, sctx.addr, opts...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d01a8bb

Please sign in to comment.