@cryptotaxi247 / netdata-1 / commits / 8e7d930ff

Small fixes2 (#20219)

* make sure supplied pointers to labels_add_already_sanitized() not null * make spinlock timeout 1 hour

Costa Tsaousis committed May 1, 2025 at 22:34 UTC 8e7d930ff5e9bcc61a5e0906ee740f414f5ca707
3 files changed +7 -6
src/database/rrdlabels.c
+3 -2
@@ -220,6 +220,8 @@ static RRDLABEL *rrdlabels_find_label_with_key_unsafe(RRDLABELS *labels, RRDLABE
220
221 static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, const char *value, RRDLABEL_SRC ls)
222 {
223 + if (unlikely(!labels || !key)) return;
224 +
225 RRDLABEL *new_label = add_label_name_value(key, value);
226
227 spinlock_lock(&labels->spinlock);
@@ -227,13 +229,12 @@ static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, con
229 RRDLABEL_SRC new_ls = (ls & ~(RRDLABEL_FLAG_NEW | RRDLABEL_FLAG_OLD));
230
231 JudyAllocThreadPulseReset();
230 - int64_t judy_mem;
232
233 Pvoid_t *PValue = JudyLIns(&labels->JudyL, (Word_t)new_label, PJE0);
234 if (!PValue || PValue == PJERR)
235 fatal("RRDLABELS: corrupted labels JudyL array");
236
236 - judy_mem = JudyAllocThreadPulseGetAndReset();
237 + int64_t judy_mem = JudyAllocThreadPulseGetAndReset();
238 RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, 0);
239
240 if(*PValue) {
src/libnetdata/locks/spinlock.c
+2 -2
@@ -9,12 +9,12 @@
9 void spinlock_deadlock_detect(usec_t *timestamp, const char *type, const char *func) {
10 if (!*timestamp) {
11 // First time checking - initialize the timestamp
12 - *timestamp = now_monotonic_high_precision_usec();
12 + *timestamp = now_monotonic_usec();
13 return;
14 }
15
16 // Check if we've exceeded the timeout
17 - usec_t now = now_monotonic_high_precision_usec();
17 + usec_t now = now_monotonic_usec();
18 if (now - *timestamp >= SPINLOCK_DEADLOCK_TIMEOUT_SEC * USEC_PER_SEC) {
19 // We've been spinning for too long - likely deadlock
20 fatal("DEADLOCK DETECTED: %s in function '%s' could not be acquired for %"PRIi64" seconds",
src/libnetdata/locks/spinlock.h
+2 -2
@@ -35,8 +35,8 @@ typedef struct netdata_spinlock
35 #define SPINLOCK_INITIALIZER { .locked = false }
36 #endif
37
38 -#define SPINLOCK_DEADLOCK_TIMEOUT_SEC 600 // Number of seconds to wait before declaring a deadlock
39 -#define SPINS_BEFORE_DEADLOCK_CHECK 20000 // Check for deadlock every 20000 spins (approx. once per second)
38 +#define SPINLOCK_DEADLOCK_TIMEOUT_SEC 3600 // Number of seconds to wait before declaring a deadlock
39 +#define SPINS_BEFORE_DEADLOCK_CHECK 100000
40
41 // Helper function to detect deadlocks
42 void spinlock_deadlock_detect(usec_t *timestamp, const char *type, const char *func);