Fix aral race condition (#21258)
Stelios Fragkakis committed
Nov 4, 2025 at 22:54 UTC
424f937df36c7e1c4c92136c8f5fc2bbfe1dd612
1 file changed
+15
-3
src/libnetdata/aral/aral.c
+15
-3
@@ -1062,12 +1062,24 @@ void aral_freez_internal(ARAL *ar, void *ptr TRACE_ALLOCATIONS_FUNCTION_DEFINITI
1062
}
1063
1064
// this is the last page with free items - keep it
1065
+ // Reset elements_segmented first to prevent new fast-path allocations
1066
+ __atomic_store_n(&page->elements_segmented, 0, __ATOMIC_RELEASE);
1067
+
1068
+ // Clear available list under its lock
1069
+ aral_page_available_lock(ar, page);
1070
page->available.list = NULL;
1066
- page->incoming_partition_bitmap = 0;
1067
- for(size_t p = 0; p < ARAL_PAGE_INCOMING_PARTITIONS; p++)
1071
+ aral_page_available_unlock(ar, page);
1072
+
1073
+ // Clear incoming partition lists under their respective locks
1074
+ // to synchronize with allocators in aral_get_free_slot___no_lock_required
1075
+ for(size_t p = 0; p < ARAL_PAGE_INCOMING_PARTITIONS; p++) {
1076
+ aral_page_incoming_lock(ar, page, p);
1077
page->incoming[p].list = NULL;
1078
+ aral_page_incoming_unlock(ar, page, p);
1079
+ }
1080
1070
- __atomic_store_n(&page->elements_segmented, 0, __ATOMIC_RELEASE);
1081
+ // Clear bitmap last with atomic operation to ensure visibility
1082
+ __atomic_store_n(&page->incoming_partition_bitmap, 0, __ATOMIC_RELEASE);
1083
__atomic_store_n(&page->refcount, 0, __ATOMIC_RELAXED);
1084
aral_unlock(ar);
1085
}