etcdserver: init server stats before passing it as argument

It is more reasonable to init the variable before passing it as an
argument.

It fixes a bug that etcdserver may panic on server stats when processing
a message from rafthttp streamReader before server stats is initialized
in server.Start().
This commit is contained in:
Yicheng Qin 2015-04-22 08:05:50 -07:00
parent b99c80874f
commit 1d96de459a

View File

@ -248,6 +248,7 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
Name: cfg.Name,
ID: id.String(),
}
sstats.Initialize()
lstats := stats.NewLeaderStats(id.String())
srv := &EtcdServer{
@ -297,7 +298,6 @@ func (s *EtcdServer) start() {
s.w = wait.New()
s.done = make(chan struct{})
s.stop = make(chan struct{})
s.stats.Initialize()
// TODO: if this is an empty log, writes all peer infos
// into the first entry
go s.run()