diff --git a/consul/server.go b/consul/server.go index c00ea50f20..4fa8cc069b 100644 --- a/consul/server.go +++ b/consul/server.go @@ -252,7 +252,10 @@ func (s *Server) Shutdown() error { if s.raft != nil { s.raftTransport.Close() s.raftLayer.Close() - s.raft.Shutdown() + future := s.raft.Shutdown() + if err := future.Error(); err != nil { + s.logger.Printf("[WARN] Error shutting down raft: %s", err) + } s.raftStore.Close() } diff --git a/consul/state_store.go b/consul/state_store.go index 113ee759b7..f1225958bb 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -154,8 +154,7 @@ func (s *StateStore) GetNode(name string) (bool, string) { } else if err != nil { panic(fmt.Errorf("Failed to get node: %v", err)) } - - return true, string(val) + return true, string(sliceCopy(val)) } // GetNodes returns all the known nodes, the slice alternates between @@ -180,7 +179,7 @@ func (s *StateStore) Nodes() []string { } else if err != nil { panic(fmt.Errorf("Failed to get nodes: %v", err)) } - nodes = append(nodes, string(key), string(val)) + nodes = append(nodes, string(sliceCopy(key)), string(sliceCopy(val))) } return nodes } @@ -301,7 +300,7 @@ func parseNodeServices(tx *mdb.Txn, dbi mdb.DBI, prefix []byte) rpc.NodeServices } // Split to get service name - parts := bytes.SplitN(key, []byte("||"), 2) + parts := bytes.SplitN(sliceCopy(key), []byte("||"), 2) service = string(parts[1]) // Setup the entry @@ -417,7 +416,7 @@ func (s *StateStore) Services() map[string][]string { } else if err != nil { panic(fmt.Errorf("Failed to get services: %v", err)) } - parts := bytes.SplitN(key, []byte("||"), 3) + parts := bytes.SplitN(sliceCopy(key), []byte("||"), 3) service := string(parts[0]) tag := string(parts[1]) @@ -520,7 +519,7 @@ func (s *StateSnapshot) Nodes() []string { } else if err != nil { panic(fmt.Errorf("Failed to get nodes: %v", err)) } - nodes = append(nodes, string(key), string(val)) + nodes = append(nodes, string(sliceCopy(key)), string(sliceCopy(val))) } return nodes } @@ -529,3 +528,9 @@ func (s *StateSnapshot) Nodes() []string { func (s *StateSnapshot) NodeServices(name string) rpc.NodeServices { return filterNodeServices(s.tx, s.dbis[1], name) } + +func sliceCopy(in []byte) []byte { + c := make([]byte, len(in)) + copy(c, in) + return c +}