@cryptotaxi247 / netdata-1 / commits / 459ee79c6

Fix race condition during journal file deletion (#21512)

Unmap journal file before deletion

Stelios Fragkakis committed Jan 3, 2026 at 09:40 UTC 459ee79c635b753331ff89621d0c18d54650d967
1 file changed +6 -4
src/database/engine/journalfile.c
+6 -4
@@ -532,7 +532,12 @@ int journalfile_destroy_unsafe(struct rrdengine_journalfile *journalfile, struct
532 if (journalfile->file)
533 (void)close_uv_file(datafile, journalfile->file);
534
535 - // This is the new journal v2 index file
535 + // Wait for all references to be released and unmap before deleting files.
536 + // This prevents SIGBUS when threads are still accessing the mmap'd data.
537 + if(journalfile_v2_data_available(journalfile))
538 + journalfile_v2_data_unmap_permanently(journalfile);
539 +
540 + // Now safe to delete the files - no threads are accessing them
541 int deleted = 0;
542 UNLINK_FILE(ctx, path_v2, ret);
543 if (ret == 0)
@@ -544,9 +549,6 @@ int journalfile_destroy_unsafe(struct rrdengine_journalfile *journalfile, struct
549
550 __atomic_add_fetch(&ctx->stats.journalfile_deletions, deleted, __ATOMIC_RELAXED);
551
547 - if(journalfile_v2_data_available(journalfile))
548 - journalfile_v2_data_unmap_permanently(journalfile);
549 -
552 return ret;
553 }
554