@cryptotaxi247 / netdata-1 / commits / c688d5123

Fix ACLK synchronization fatal on shutdown (#20034)

* Add libuv close callback to improve handle management and replace duplicate code Check if the handle is closing before attempting a close * Do not close handle * Disable handle check for now * Fix typo * Delete commented out code * Simplify code

Stelios Fragkakis committed Apr 3, 2025 at 10:41 UTC c688d51231e25d63d09f5dcdccba0c5eadc70d9d
4 files changed +15 -30
src/daemon/libuv_workers.c
+11
@@ -128,3 +128,14 @@ int create_uv_thread(uv_thread_t *thread, uv_thread_cb thread_func, void *arg, i
128
129 return err;
130 }
131 +
132 +void libuv_close_callback(uv_handle_t *handle, void *data __maybe_unused)
133 +{
134 + // Only close handles that aren't already closing
135 + if (!uv_is_closing(handle)) {
136 + if (handle->type == UV_TIMER) {
137 + uv_timer_stop((uv_timer_t *)handle);
138 + }
139 + uv_close(handle, NULL);
140 + }
141 +}
src/daemon/libuv_workers.h
+1
@@ -89,5 +89,6 @@ enum event_loop_job {
89
90 void register_libuv_worker_jobs();
91 int create_uv_thread(uv_thread_t *thread, uv_thread_cb thread_func, void *arg, int *retries);
92 +void libuv_close_callback(uv_handle_t *handle, void *data __maybe_unused);
93
94 #endif //NETDATA_EVENT_LOOP_H
src/database/sqlite/sqlite_aclk.c
+2 -20
@@ -528,15 +528,6 @@ static void node_update_timer_cb(uv_timer_t *handle)
528 uv_timer_stop(&ahc->timer);
529 }
530
531 -static void close_callback(uv_handle_t *handle, void *data __maybe_unused)
532 -{
533 - if (handle->type == UV_TIMER) {
534 - uv_timer_stop((uv_timer_t *)handle);
535 - }
536 -
537 - uv_close(handle, NULL); // Automatically close and free the handle
538 -}
539 -
531 static void after_start_alert_push(uv_work_t *req, int status __maybe_unused)
532 {
533 struct worker_data *data = req->data;
@@ -881,9 +872,7 @@ static void aclk_synchronization_event_loop(void *arg)
872 uv_close((uv_handle_t *)&config->timer_req, NULL);
873
874 uv_close((uv_handle_t *)&config->async, NULL);
884 - uv_run(loop, UV_RUN_NOWAIT);
885 -
886 - uv_walk(loop, (uv_walk_cb) close_callback, NULL);
875 + uv_walk(loop, libuv_close_callback, NULL);
876 uv_run(loop, UV_RUN_NOWAIT);
877
878 (void) uv_loop_close(loop);
@@ -953,16 +942,9 @@ void create_aclk_config(RRDHOST *host __maybe_unused, nd_uuid_t *host_uuid __may
942
943 void destroy_aclk_config(RRDHOST *host)
944 {
956 - struct aclk_sync_cfg_t *ahc;
957 - if (!host || !(ahc = host->aclk_config))
945 + if (!host || !host->aclk_config)
946 return;
947
960 - if (ahc->timer_initialized) {
961 - if (uv_is_active((uv_handle_t *)&ahc->timer))
962 - uv_timer_stop(&ahc->timer);
963 - uv_close((uv_handle_t *)&ahc->timer, NULL);
964 - }
965 -
948 freez(host->aclk_config);
949 host->aclk_config = NULL;
950 }
src/database/sqlite/sqlite_metadata.c
+1 -10
@@ -2481,15 +2481,6 @@ static void start_metadata_hosts(uv_work_t *req)
2481 worker_is_idle();
2482 }
2483
2484 -static void close_callback(uv_handle_t *handle, void *data __maybe_unused)
2485 -{
2486 - if (handle->type == UV_TIMER) {
2487 - uv_timer_stop((uv_timer_t *)handle);
2488 - }
2489 -
2490 - uv_close(handle, NULL); // Automatically close and free the handle
2491 -}
2492 -
2484 #define EVENT_LOOP_NAME "METASYNC"
2485
2486 static void metadata_event_loop(void *arg)
@@ -2695,7 +2686,7 @@ static void metadata_event_loop(void *arg)
2686 }
2687 config->initialized = false;
2688
2698 - uv_walk(loop, (uv_walk_cb) close_callback, NULL);
2689 + uv_walk(loop, libuv_close_callback, NULL);
2690 uv_run(loop, UV_RUN_NOWAIT);
2691
2692 int rc;