Skip to content

Commit 2eb7bc8

Browse files
authored
fix(export-backup): fix memory leak in backup export (#7452)
There was a memory leak because the program exits before DB close.
1 parent 4fb4ff2 commit 2eb7bc8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

worker/export.go

-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ func exportInternal(ctx context.Context, in *pb.ExportRequest, db *badger.DB,
607607
return false
608608
}
609609

610-
fmt.Println(pk)
611610
// Do not pick keys storing parts of a multi-part list. They will be read
612611
// from the main key.
613612
if pk.HasStartUid {

worker/file_handler.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ func (h *fileHandler) ExportBackup(backupDir, exportDir, format string,
363363
ch <- errors.Wrapf(err, "cannot open DB at %s", dir)
364364
return
365365
}
366-
defer db.Close()
367366

368367
req := &pb.ExportRequest{
369368
GroupId: group,
@@ -375,6 +374,9 @@ func (h *fileHandler) ExportBackup(backupDir, exportDir, format string,
375374
}
376375

377376
_, err = exportInternal(context.Background(), req, db, true)
377+
// It is important to close the db before sending err to ch. Else, we will see a memory
378+
// leak.
379+
db.Close()
378380
ch <- errors.Wrapf(err, "cannot export data inside DB at %s", dir)
379381
}(gid)
380382
}

0 commit comments

Comments
 (0)