etcdserver: close mvcc.KV on init error path

Scheduled compaction will panic if KV is not stopped before
closing the backend.
release-3.2
Anthony Romano 2017-05-22 15:36:07 -07:00
parent f75e333264
commit c1c9a2c96c
1 changed files with 9 additions and 0 deletions

View File

@ -450,6 +450,15 @@ func NewServer(cfg *ServerConfig) (srv *EtcdServer, err error) {
plog.Warningf("consistent index never saved (snapshot index=%d)", snapshot.Metadata.Index)
}
}
newSrv := srv // since srv == nil in defer if srv is returned as nil
defer func() {
// closing backend without first closing kv can cause
// resumed compactions to fail with closed tx errors
if err != nil {
newSrv.kv.Close()
}
}()
srv.consistIndex.setConsistentIndex(srv.kv.ConsistentIndex())
tp, err := auth.NewTokenProvider(cfg.AuthToken,
func(index uint64) <-chan struct{} {