@cryptotaxi247 / netdata-1 / commits / 1c71da441

Detect self thread when exiting. (#17126)

Skip waiting when a static thread causes the agent to exit (eg. the service thread by calling a fatal).

vkalintiris committed Mar 8, 2024 at 10:12 UTC 1c71da44145f799f5ffa6bdefc2b557deb1e5bdd
1 file changed +8 -2
src/daemon/main.c
+8 -2
@@ -680,8 +680,14 @@ void cancel_main_threads() {
680 sleep_usec(step);
681 found = 0;
682 for (i = 0; static_threads[i].name != NULL ; i++) {
683 - if (static_threads[i].enabled != NETDATA_MAIN_THREAD_EXITED)
684 - found++;
683 + if (static_threads[i].enabled == NETDATA_MAIN_THREAD_EXITED)
684 + continue;
685 +
686 + // Don't wait ourselves.
687 + if (static_threads[i].thread && (*static_threads[i].thread == pthread_self()))
688 + continue;
689 +
690 + found++;
691 }
692 }
693