Skip to content

Commit 073d310

Browse files
committed
fix(export-backup): fix memory leak in backup export (#7452)
There was a memory leak because the program exits before DB close. (cherry picked from commit 2eb7bc8)
1 parent 9cd147e commit 073d310

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

worker/file_handler.go

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

371370
req := &pb.ExportRequest{
372371
GroupId: group,
@@ -377,6 +376,9 @@ func (h *fileHandler) ExportBackup(backupDir, exportDir, format string,
377376
}
378377

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

0 commit comments

Comments
 (0)