diff --git a/command/agent/dns.go b/command/agent/dns.go index ec56fbfc5b..41f8df57ba 100644 --- a/command/agent/dns.go +++ b/command/agent/dns.go @@ -274,7 +274,7 @@ func (d *DNSServer) handleTest(resp dns.ResponseWriter, req *dns.Msg) { m.Authoritative = true m.RecursionAvailable = true header := dns.RR_Header{Name: q.Name, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0} - txt := &dns.TXT{header, []string{"ok"}} + txt := &dns.TXT{Hdr: header, Txt: []string{"ok"}} m.Answer = append(m.Answer, txt) d.addSOA(consulDomain, m) if err := resp.WriteMsg(m); err != nil { diff --git a/command/watch.go b/command/watch.go index 0ad514b920..d5caf325a4 100644 --- a/command/watch.go +++ b/command/watch.go @@ -144,14 +144,18 @@ func (c *WatchCommand) Run(args []string) int { } // Setup handler - errExit := false + + // errExit: + // 0: false + // 1: true + errExit := 0 if script == "" { wp.Handler = func(idx uint64, data interface{}) { defer wp.Stop() buf, err := json.MarshalIndent(data, "", " ") if err != nil { c.Ui.Error(fmt.Sprintf("Error encoding output: %s", err)) - errExit = true + errExit = 1 } c.Ui.Output(string(buf)) } @@ -186,7 +190,7 @@ func (c *WatchCommand) Run(args []string) int { return ERR: wp.Stop() - errExit = true + errExit = 1 } } @@ -203,12 +207,7 @@ func (c *WatchCommand) Run(args []string) int { return 1 } - // Handle an error exit - if errExit { - return 1 - } else { - return 0 - } + return errExit } func (c *WatchCommand) Synopsis() string { diff --git a/consul/fsm.go b/consul/fsm.go index a6b7c3bb5f..9031370448 100644 --- a/consul/fsm.go +++ b/consul/fsm.go @@ -1,6 +1,7 @@ package consul import ( + "errors" "fmt" "io" "io/ioutil" @@ -164,8 +165,9 @@ func (c *consulFSM) applyKVSOperation(buf []byte, index uint64) interface{} { return act } default: - c.logger.Printf("[WARN] consul.fsm: Invalid KVS operation '%s'", req.Op) - return fmt.Errorf("Invalid KVS operation '%s'", req.Op) + err := errors.New(fmt.Sprintf("Invalid KVS operation '%s'", req.Op)) + c.logger.Printf("[WARN] consul.fsm: %v", err) + return err } } diff --git a/consul/pool.go b/consul/pool.go index 523cfd5253..048e2e6e2f 100644 --- a/consul/pool.go +++ b/consul/pool.go @@ -259,27 +259,28 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) { } // Wrap the connection - c := &Conn{ - refCount: 1, - addr: addr, - session: session, - clients: list.New(), - lastUsed: time.Now(), - version: version, - pool: p, - } + var c *Conn // Track this connection, handle potential race condition p.Lock() + defer p.Unlock() + if existing := p.pool[addr.String()]; existing != nil { - c.Close() - p.Unlock() - return existing, nil + c = existing } else { + c = &Conn{ + refCount: 1, + addr: addr, + session: session, + clients: list.New(), + lastUsed: time.Now(), + version: version, + pool: p, + } p.pool[addr.String()] = c - p.Unlock() - return c, nil } + + return c, nil } // clearConn is used to clear any cached connection, potentially in response to an erro