4
5
extern struct config stream_config;
6
7
+void destroy_receiver_state(struct receiver_state *rpt) {
8
+ freez(rpt->key);
9
+ freez(rpt->hostname);
10
+ freez(rpt->registry_hostname);
11
+ freez(rpt->machine_guid);
12
+ freez(rpt->os);
13
+ freez(rpt->timezone);
14
+ freez(rpt->tags);
15
+ freez(rpt->client_ip);
16
+ freez(rpt->client_port);
17
+ freez(rpt->program_name);
18
+ freez(rpt->program_version);
19
+#ifdef ENABLE_HTTPS
20
+ if(rpt->ssl.conn){
21
+ SSL_free(rpt->ssl.conn);
22
+ }
23
+#endif
24
+ freez(rpt);
25
+}
26
+
27
static void rrdpush_receiver_thread_cleanup(void *ptr) {
28
static __thread int executed = 0;
29
if(!executed) {
30
executed = 1;
31
struct receiver_state *rpt = (struct receiver_state *) ptr;
32
+ // If the shutdown sequence has started, and this receiver is still attached to the host then we cannot touch
33
+ // the host pointer as it is unpredicable when the RRDHOST is deleted. Do the cleanup from rrdhost_free().
34
+ if (netdata_exit && rpt->host) {
35
+ rpt->exited = 1;
36
+ return;
37
+ }
38
39
// Make sure that we detach this thread and don't kill a freshly arriving receiver
14
- if (rpt->host) {
40
+ if (!netdata_exit && rpt->host) {
41
netdata_mutex_lock(&rpt->host->receiver_lock);
42
if (rpt->host->receiver == rpt)
43
rpt->host->receiver = NULL;
45
}
46
47
info("STREAM %s [receive from [%s]:%s]: receive thread ended (task id %d)", rpt->hostname, rpt->client_ip, rpt->client_port, gettid());
22
-
23
- freez(rpt->key);
24
- freez(rpt->hostname);
25
- freez(rpt->registry_hostname);
26
- freez(rpt->machine_guid);
27
- freez(rpt->os);
28
- freez(rpt->timezone);
29
- freez(rpt->tags);
30
- freez(rpt->client_ip);
31
- freez(rpt->client_port);
32
- freez(rpt->program_name);
33
- freez(rpt->program_version);
34
-#ifdef ENABLE_HTTPS
35
- if(rpt->ssl.conn){
36
- SSL_free(rpt->ssl.conn);
37
- }
38
-#endif
39
- freez(rpt);
40
-
48
+ destroy_receiver_state(rpt);
49
}
50
}
51
421
422
423
size_t count = streaming_parser(rpt, &cd, fp);
416
- //size_t count = pluginsd_process(host, &cd, fp, 1);
417
-
418
- log_stream_connection(rpt->client_ip, rpt->client_port, rpt->key, rpt->host->machine_guid, rpt->host->hostname, "DISCONNECTED");
419
- error("STREAM %s [receive from [%s]:%s]: disconnected (completed %zu updates).", rpt->host->hostname, rpt->client_ip, rpt->client_port, count);
420
-
421
- netdata_mutex_lock(&rpt->host->receiver_lock);
422
- if (rpt->host->receiver == rpt) {
423
- rrdhost_wrlock(rpt->host);
424
- rpt->host->senders_disconnected_time = now_realtime_sec();
425
- rrdhost_flag_set(rpt->host, RRDHOST_FLAG_ORPHAN);
426
- if(health_enabled == CONFIG_BOOLEAN_AUTO)
427
- rpt->host->health_enabled = 0;
428
- rrdhost_unlock(rpt->host);
429
- rrdpush_sender_thread_stop(rpt->host);
424
+
425
+ log_stream_connection(rpt->client_ip, rpt->client_port, rpt->key, rpt->host->machine_guid, rpt->hostname,
426
+ "DISCONNECTED");
427
+ error("STREAM %s [receive from [%s]:%s]: disconnected (completed %zu updates).", rpt->hostname, rpt->client_ip,
428
+ rpt->client_port, count);
429
+
430
+ // During a shutdown there is cleanup code in rrdhost that will cancel the sender thread
431
+ if (!netdata_exit && rpt->host) {
432
+ netdata_mutex_lock(&rpt->host->receiver_lock);
433
+ if (rpt->host->receiver == rpt) {
434
+ rrdhost_wrlock(rpt->host);
435
+ rpt->host->senders_disconnected_time = now_realtime_sec();
436
+ rrdhost_flag_set(rpt->host, RRDHOST_FLAG_ORPHAN);
437
+ if(health_enabled == CONFIG_BOOLEAN_AUTO)
438
+ rpt->host->health_enabled = 0;
439
+ rrdhost_unlock(rpt->host);
440
+ rrdpush_sender_thread_stop(rpt->host);
441
+ }
442
+ netdata_mutex_unlock(&rpt->host->receiver_lock);
443
}
431
- netdata_mutex_unlock(&rpt->host->receiver_lock);
444
445
// cleanup
446
fclose(fp);
435
-
447
return (int)count;
448
}
449