diff --git a/etcdserver/server.go b/etcdserver/server.go index de2fb22fa4f..e34fafbdd5f 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -265,7 +265,22 @@ func NewServer(cfg *ServerConfig) (srv *EtcdServer, err error) { bepath := path.Join(cfg.SnapDir(), databaseFilename) beExist := fileutil.Exist(bepath) - be := backend.NewDefaultBackend(bepath) + + var be backend.Backend + beOpened := make(chan struct{}) + go func() { + be = backend.NewDefaultBackend(bepath) + beOpened <- struct{}{} + }() + + select { + case <-beOpened: + case <-time.After(time.Second): + plog.Warningf("another etcd process is running with the same data dir and holding the file lock.") + plog.Warningf("waiting for it to exit before starting...") + <-beOpened + } + defer func() { if err != nil { be.Close()