@cryptotaxi247 / netdata-1 / commits / 695b9aa0c

statsd cleanup threads on shutdown to prevent crash

Costa Tsaousis (ktsaou) committed Jul 16, 2017 at 05:13 UTC 695b9aa0cf1a0f551eabe561b302eead1cf9fd66
1 file changed +14 -4
src/statsd.c
+14 -4
@@ -874,7 +874,6 @@ void statsd_collector_thread_cleanup(void *data) {
874 #endif
875
876 freez(d);
877 - listen_sockets_close(&statsd.sockets);
877 }
878
879 void *statsd_collector_thread(void *ptr) {
@@ -1735,6 +1734,16 @@ int statsd_listen_sockets_setup(void) {
1734 return listen_sockets_setup(&statsd.sockets);
1735 }
1736
1737 +void statsd_main_cleanup(void *data) {
1738 + pthread_t *threads = data;
1739 +
1740 + int i;
1741 + for(i = 0; i < statsd.threads ;i++)
1742 + pthread_cancel(threads[i]);
1743 +
1744 + listen_sockets_close(&statsd.sockets);
1745 +}
1746 +
1747 void *statsd_main(void *ptr) {
1748 (void)ptr;
1749
@@ -1846,7 +1855,9 @@ void *statsd_main(void *ptr) {
1855 error("STATSD: cannot request detach of child thread.");
1856 }
1857
1849 - // ----------------------------------------------------------------------------------------------------------------
1858 + pthread_cleanup_push(statsd_main_cleanup, &threads);
1859 +
1860 + // ----------------------------------------------------------------------------------------------------------------
1861 // statsd monitoring charts
1862
1863 RRDSET *st_metrics = rrdset_create_localhost(
@@ -2023,8 +2034,7 @@ void *statsd_main(void *ptr) {
2034 break;
2035 }
2036
2026 - for(i = 0; i < statsd.threads ;i++)
2027 - pthread_cancel(threads[i]);
2037 + pthread_cleanup_pop(1);
2038
2039 pthread_exit(NULL);
2040 return NULL;