@cryptotaxi247 / netdata-1 / commits / 5af71b875

Acquire receiver_lock to to avoid race condition (#16531)

Stelios Fragkakis committed Dec 4, 2023 at 21:05 UTC 5af71b8755546cba56ef3460c584927a3ca2163c
1 file changed +20 -23
daemon/service.c
+20 -23
@@ -204,25 +204,19 @@ static void svc_rrdhost_detect_obsolete_charts(RRDHOST *host) {
204 time_t now = now_realtime_sec();
205 time_t last_entry_t;
206 RRDSET *st;
207 +
208 + time_t child_connect_time = host->child_connect_time;
209 +
210 rrdset_foreach_read(st, host) {
211 if(rrdset_is_replicating(st))
212 continue;
213
214 last_entry_t = rrdset_last_entry_s(st);
215
213 -// if(last_entry_t + st->update_every * 2 + 30 < now)
214 -// netdata_log_error("Possibly obsolete chart 'host:%s/chart:%s', last entry is %zu secs old "
215 -// "(replicating: %s, obsolete: %s, obsolete dims: %s)",
216 -// rrdhost_hostname(host), rrdset_id(st), now - last_entry_t,
217 -// rrdset_is_replicating(st) ? "true" : "false",
218 -// rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) ? "true" : "false",
219 -// rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE_DIMENSIONS) ? "true" : "false"
220 -// );
221 -
222 -
223 - if(last_entry_t && last_entry_t < host->child_connect_time &&
224 - host->child_connect_time + TIME_TO_RUN_OBSOLETIONS_ON_CHILD_CONNECT +
225 - (ITERATIONS_TO_RUN_OBSOLETIONS_ON_CHILD_CONNECT * st->update_every) < now)
216 + if (last_entry_t && last_entry_t < child_connect_time &&
217 + child_connect_time + TIME_TO_RUN_OBSOLETIONS_ON_CHILD_CONNECT +
218 + (ITERATIONS_TO_RUN_OBSOLETIONS_ON_CHILD_CONNECT * st->update_every) <
219 + now)
220
221 rrdset_is_obsolete___safe_from_collector_thread(st);
222 }
@@ -241,19 +235,22 @@ static void svc_rrd_cleanup_obsolete_charts_from_all_hosts() {
235
236 svc_rrdhost_cleanup_charts_marked_obsolete(host);
237
244 - if(host != localhost
245 - && host->trigger_chart_obsoletion_check
246 - && (
247 - (
248 - host->child_last_chart_command
249 - && host->child_last_chart_command + host->health.health_delay_up_to < now_realtime_sec()
250 - )
251 - || (host->child_connect_time + TIME_TO_RUN_OBSOLETIONS_ON_CHILD_CONNECT < now_realtime_sec())
252 - )
253 - ) {
238 + if (host == localhost)
239 + continue;
240 +
241 + netdata_mutex_lock(&host->receiver_lock);
242 +
243 + time_t now = now_realtime_sec();
244 +
245 + if (host->trigger_chart_obsoletion_check &&
246 + ((host->child_last_chart_command &&
247 + host->child_last_chart_command + host->health.health_delay_up_to < now) ||
248 + (host->child_connect_time + TIME_TO_RUN_OBSOLETIONS_ON_CHILD_CONNECT < now))) {
249 svc_rrdhost_detect_obsolete_charts(host);
250 host->trigger_chart_obsoletion_check = 0;
251 }
252 +
253 + netdata_mutex_unlock(&host->receiver_lock);
254 }
255
256 rrd_unlock();