@cryptotaxi247 / netdata-1 / commits / 60c5371d6

Improve service thread shutdown (#16841)

Shutdown service thread first Service thread sleep 1 sec at a time

Stelios Fragkakis committed Jan 26, 2024 at 13:00 UTC 60c5371d686644ecc409ae68499e4fff7a3547e7
2 files changed +13 -7
daemon/main.c
+6 -6
@@ -357,6 +357,12 @@ void netdata_cleanup_and_exit(int ret, const char *action, const char *action_re
357 | SERVICE_ACLKSYNC
358 );
359
360 + delta_shutdown_time("stop maintenance thread");
361 +
362 + timeout = !service_wait_exit(
363 + SERVICE_MAINTENANCE
364 + , 3 * USEC_PER_SEC);
365 +
366 delta_shutdown_time("stop replication, exporters, health and web servers threads");
367
368 timeout = !service_wait_exit(
@@ -394,12 +400,6 @@ void netdata_cleanup_and_exit(int ret, const char *action, const char *action_re
400 SERVICE_CONTEXT
401 , 3 * USEC_PER_SEC);
402
397 - delta_shutdown_time("stop maintenance thread");
398 -
399 - timeout = !service_wait_exit(
400 - SERVICE_MAINTENANCE
401 - , 3 * USEC_PER_SEC);
402 -
403 delta_shutdown_time("clear web client cache");
404
405 web_client_cache_destroy();
daemon/service.c
+7 -1
@@ -307,12 +307,18 @@ void *service_main(void *ptr)
307 heartbeat_t hb;
308 heartbeat_init(&hb);
309 usec_t step = USEC_PER_SEC * SERVICE_HEARTBEAT;
310 + usec_t real_step = USEC_PER_SEC;
311
312 netdata_log_debug(D_SYSTEM, "Service thread starts");
313
314 while (service_running(SERVICE_MAINTENANCE)) {
315 worker_is_idle();
315 - heartbeat_next(&hb, step);
316 + heartbeat_next(&hb, USEC_PER_SEC);
317 + if (real_step < step) {
318 + real_step += USEC_PER_SEC;
319 + continue;
320 + }
321 + real_step = USEC_PER_SEC;
322
323 svc_rrd_cleanup_obsolete_charts_from_all_hosts();
324 svc_rrdhost_cleanup_orphan_hosts(localhost);