@cryptotaxi247 / netdata-1 / commits / 2b9075831

Cleanup the main exporting engine thread on exit (#7558)

Vladimir Kobal committed Dec 17, 2019 at 22:21 UTC 2b9075831d8e9fabb27238e9fa0b344b38600a4b
1 file changed +17 -6
exporting/exporting_engine.c
+17 -6
@@ -2,6 +2,15 @@
2
3 #include "exporting_engine.h"
4
5 +static void exporting_main_cleanup(void *ptr) {
6 + struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
7 + static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
8 +
9 + info("cleaning up...");
10 +
11 + static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
12 +}
13 +
14 /**
15 * Exporting engine main
16 *
@@ -13,17 +22,17 @@
22 */
23 void *exporting_main(void *ptr)
24 {
16 - (void)ptr;
25 + netdata_thread_cleanup_push(exporting_main_cleanup, ptr);
26
27 struct engine *engine = read_exporting_config();
28 if (!engine) {
29 info("EXPORTING: no exporting connectors configured");
21 - return NULL;
30 + goto cleanup;
31 }
32
33 if (init_connectors(engine) != 0) {
34 error("EXPORTING: cannot initialize exporting connectors");
26 - return NULL;
35 + goto cleanup;
36 }
37
38 usec_t step_ut = localhost->rrd_update_every * USEC_PER_SEC;
@@ -37,18 +46,18 @@ void *exporting_main(void *ptr)
46 if (mark_scheduled_instances(engine)) {
47 if (prepare_buffers(engine) != 0) {
48 error("EXPORTING: cannot prepare data to send");
40 - return NULL;
49 + break;
50 }
51 }
52
53 if (notify_workers(engine) != 0) {
54 error("EXPORTING: cannot communicate with exporting connector instance working threads");
46 - return NULL;
55 + break;
56 }
57
58 if (send_internal_metrics(engine) != 0) {
59 error("EXPORTING: cannot send metrics for the operation of exporting engine");
51 - return NULL;
60 + break;
61 }
62
63 #ifdef UNIT_TESTING
@@ -56,5 +65,7 @@ void *exporting_main(void *ptr)
65 #endif
66 }
67
68 +cleanup:
69 + netdata_thread_cleanup_pop(1);
70 return NULL;
71 }