Skip to content

Commit

Permalink
etcdserver: delete member directory when NewServer errors
Browse files Browse the repository at this point in the history
This is for etcd-io#3827.
This removes member directory with defer statement. And it removes only when
etcdserver.NewServer returns error.
  • Loading branch information
gyuho committed Dec 29, 2015
1 parent 6c5dc28 commit 68e2532
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ type EtcdServer struct {
// NewServer creates a new EtcdServer from the supplied configuration. The
// configuration is considered static for the lifetime of the EtcdServer.
func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
isSuccess := false
defer func() {
if !isSuccess {
// It removes member directory when NewServer returns error.
// This prevents conflicts with 'proxy' directory when
// the node falls back to proxy.
os.RemoveAll(cfg.MemberDir())
}
}()

st := store.New(StoreClusterPrefix, StoreKeysPrefix)
var (
w *wal.WAL
Expand Down Expand Up @@ -394,6 +404,7 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
}
srv.r.transport = tr

isSuccess = true
return srv, nil
}

Expand Down

0 comments on commit 68e2532

Please sign in to comment.