properly cleanup static workers
Costa Tsaousis (ktsaou) committed
Jan 8, 2018 at 00:56 UTC
4293aa67ce95d68b0680e61d11973f1acc97aff0
1 file changed
+15
-7
src/web_server.c
+15
-7
@@ -523,7 +523,8 @@ static int web_server_snd_callback(int fd, int socktype, void *data, short int *
523
}
524
525
static void socket_listen_main_static_threaded_worker_cleanup(void *ptr) {
526
- (void)ptr;
526
+ int *running = (int *)ptr;
527
+ *running = 0;
528
529
info("stopped after %zu connects, %zu disconnects, %zu receptions and %zu sends",
530
web_server_static_connected,
@@ -534,7 +535,8 @@ static void socket_listen_main_static_threaded_worker_cleanup(void *ptr) {
535
}
536
537
void *socket_listen_main_static_threaded_worker(void *ptr) {
537
- (void)ptr;
538
+ int *running = (int *)ptr;
539
+ *running = 1;
540
541
netdata_thread_cleanup_push(socket_listen_main_static_threaded_worker_cleanup, ptr);
542
@@ -553,6 +555,7 @@ void *socket_listen_main_static_threaded_worker(void *ptr) {
555
556
static long long static_threaded_threads_count = 1;
557
static netdata_thread_t *static_threaded_threads_ids = NULL;
558
+static volatile int *static_threaded_threads_running = NULL;
559
560
static void socket_listen_main_static_threaded_cleanup(void *ptr) {
561
struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
@@ -561,11 +564,15 @@ static void socket_listen_main_static_threaded_cleanup(void *ptr) {
564
565
int i;
566
for(i = 1; i < static_threaded_threads_count; i++) {
564
- info("stopping worker %d", i+1);
565
- netdata_thread_cancel(static_threaded_threads_ids[i]);
567
+ if(static_threaded_threads_running[i]) {
568
+ info("stopping worker %d", i + 1);
569
+ netdata_thread_cancel(static_threaded_threads_ids[i]);
570
+ }
571
+ else
572
+ info("found stopped worker %d", i + 1);
573
}
574
568
- info("cleaning up...");
575
+ info("closing all web server sockets...");
576
listen_sockets_close(&api_sockets);
577
}
578
}
@@ -586,6 +593,7 @@ void *socket_listen_main_static_threaded(void *ptr) {
593
if(static_threaded_threads_count < 1) static_threaded_threads_count = 1;
594
595
static_threaded_threads_ids = callocz((size_t)static_threaded_threads_count, sizeof(netdata_thread_t));
596
+ static_threaded_threads_running = callocz((size_t)static_threaded_threads_count, sizeof(int));
597
598
int i;
599
for(i = 1; i < static_threaded_threads_count; i++) {
@@ -593,11 +601,11 @@ void *socket_listen_main_static_threaded(void *ptr) {
601
snprintfz(tag, 50, "WEB_SERVER[static%d]", i+1);
602
603
info("starting worker %d", i+1);
596
- netdata_thread_create(&static_threaded_threads_ids[i], tag, NETDATA_THREAD_OPTION_DEFAULT, socket_listen_main_static_threaded_worker, NULL);
604
+ netdata_thread_create(&static_threaded_threads_ids[i], tag, NETDATA_THREAD_OPTION_DEFAULT, socket_listen_main_static_threaded_worker, (void *)&static_threaded_threads_running[i]);
605
}
606
607
// and the main one
600
- socket_listen_main_static_threaded_worker(NULL);
608
+ socket_listen_main_static_threaded_worker((void *)&static_threaded_threads_running[0]);
609
610
netdata_thread_cleanup_pop(1);
611
return NULL;