Skip to content

Commit 0acd205

Browse files
FIX (restores): Fix order of temp files closing that causes flaky tests
1 parent d678f9b commit 0acd205

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ func (uc *CreatePostgresqlBackupUsecase) streamToStorage(
255255
copyResultCh <- err
256256
}()
257257

258-
// Wait for the dump and copy to finish
259-
waitErr := cmd.Wait()
258+
// Wait for the copy to finish first, then the dump process
260259
copyErr := <-copyResultCh
261260
bytesWritten := <-bytesWrittenCh
261+
waitErr := cmd.Wait()
262262

263263
// Check for shutdown before finalizing
264264
if config.IsShouldShutdown() {

backend/internal/features/storages/models/local/model.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func (l *LocalStorage) SaveFile(logger *slog.Logger, fileID uuid.UUID, file io.R
6262
return fmt.Errorf("failed to sync temp file: %w", err)
6363
}
6464

65+
// Close the temp file explicitly before moving it (required on Windows)
66+
if err = tempFile.Close(); err != nil {
67+
logger.Error("Failed to close temp file", "fileId", fileID.String(), "error", err)
68+
return fmt.Errorf("failed to close temp file: %w", err)
69+
}
70+
6571
finalPath := filepath.Join(config.GetEnv().DataFolder, fileID.String())
6672
logger.Debug(
6773
"Moving file from temp to final location",

0 commit comments

Comments
 (0)