From c33d04fb54b216b7350d1d09178776db427727c0 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 1 Nov 2016 17:55:16 -0700 Subject: [PATCH] etcdserver: print out warning when waiting for file lock --- etcdserver/server.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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()