Skip to content

Commit 38e0829

Browse files
author
Bill
committed
fix(backup): await async operations in scheduled backup interval
Greptile review found that setInterval callback was not awaiting the async createBackup() and pruneBackups() calls, which would cause unhandled promise rejections instead of being caught by the try/catch block.
1 parent fc7373a commit 38e0829

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/modules/backup.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ let scheduledBackupInterval = null;
3838
*/
3939
export async function getBackupDir(dir) {
4040
const backupDir = dir ?? DEFAULT_BACKUP_DIR;
41-
try {
42-
await access(backupDir, constants.F_OK);
43-
} catch {
44-
await mkdir(backupDir, { recursive: true });
45-
}
41+
// Use recursive mkdir to avoid race condition between check and create
42+
await mkdir(backupDir, { recursive: true });
4643
return backupDir;
4744
}
4845

@@ -402,10 +399,10 @@ export function startScheduledBackups(opts = {}) {
402399

403400
info('Starting scheduled config backups', { intervalMs });
404401

405-
scheduledBackupInterval = setInterval(() => {
402+
scheduledBackupInterval = setInterval(async () => {
406403
try {
407-
createBackup(backupDir);
408-
pruneBackups(retention, backupDir);
404+
await createBackup(backupDir);
405+
await pruneBackups(retention, backupDir);
409406
} catch (err) {
410407
logError('Scheduled backup failed', { error: err.message });
411408
}

0 commit comments

Comments
 (0)