From 7bd77c2e62871809475ec6c0837b79520dbf2e05 Mon Sep 17 00:00:00 2001 From: "shitao.lst" Date: Wed, 21 Jun 2023 17:50:37 +0800 Subject: [PATCH] etcdutl: fix db double closed Signed-off-by: shitao.lst --- etcdutl/snapshot/v3_snapshot.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/etcdutl/snapshot/v3_snapshot.go b/etcdutl/snapshot/v3_snapshot.go index 8958ba80da1..d9837b803a6 100644 --- a/etcdutl/snapshot/v3_snapshot.go +++ b/etcdutl/snapshot/v3_snapshot.go @@ -340,13 +340,8 @@ func (s *v3Manager) copyAndVerifyDB() error { if dberr != nil { return dberr } - dbClosed := false - defer func() { - if !dbClosed { - db.Close() - dbClosed = true - } - }() + defer db.Close() + if _, err := io.Copy(db, srcf); err != nil { return err } @@ -383,7 +378,7 @@ func (s *v3Manager) copyAndVerifyDB() error { } // db hash is OK, can now modify DB so it can be part of a new cluster - db.Close() + return nil }