@cryptotaxi247 / netdata-1 / commits / 5b8a54405

Fix ACLK Backoff Timeout Logic (#20095)

* Fix delay calculation to return values in milliseconds * Revert this change, the value accepted should be in ms

Stelios Fragkakis committed Apr 9, 2025 at 14:05 UTC 5b8a544053dd68d50e022234025b551932efb3a2
2 files changed +9 -6
src/aclk/aclk_util.c
+8 -5
@@ -332,7 +332,7 @@ const char *aclk_topic_cache_iterate(size_t *iter)
332 *
333 */
334
335 -unsigned long int aclk_tbeb_delay(int reset, int base, unsigned long int min, unsigned long int max) {
335 +unsigned long int aclk_tbeb_delay(int reset, int base, unsigned long int mins_ms, unsigned long int min_ms) {
336 static int attempt = -1;
337
338 if (reset) {
@@ -350,11 +350,14 @@ unsigned long int aclk_tbeb_delay(int reset, int base, unsigned long int min, un
350
351 delay += (os_random32() % (MAX(1000, delay/2)));
352
353 - if (delay <= min * MSEC_PER_SEC)
354 - return min;
353 + // Note: this is a bug, the value expected from the env backoff payload should be in seconds
354 + // but the code here is in milliseconds. To avoid confusion the cloud will be sending the value
355 + // in milliseconds so that the code will work as expected.
356 + if (delay <= mins_ms * MSEC_PER_SEC)
357 + return mins_ms;
358
356 - if (delay >= max * MSEC_PER_SEC)
357 - return max;
359 + if (delay >= min_ms * MSEC_PER_SEC)
360 + return min_ms;
361
362 return delay;
363 }
src/aclk/aclk_util.h
+1 -1
@@ -103,7 +103,7 @@ extern volatile int aclk_conversation_log_counter;
103 #define ACLK_GET_CONV_LOG_NEXT() __atomic_fetch_add(&aclk_conversation_log_counter, 1, __ATOMIC_SEQ_CST)
104 #endif
105
106 -unsigned long int aclk_tbeb_delay(int reset, int base, unsigned long int min, unsigned long int max);
106 +unsigned long int aclk_tbeb_delay(int reset, int base, unsigned long int mins_ms, unsigned long int min_ms);
107 #define aclk_tbeb_reset(x) aclk_tbeb_delay(1, 0, 0, 0)
108
109 void aclk_set_proxy(char **ohost, int *port, char **uname, char **pwd, enum mqtt_wss_proxy_type *type);