shutdown while waiting for collectors to finish (#16023)
call cleanup_destroyed_dictionaries() while waiting for collectors to finish
Costa Tsaousis committed
Oct 21, 2023 at 11:02 UTC
babb3c129c4abcf619f221664b88a10914ed493f
3 files changed
+14
-2
daemon/main.c
+1
@@ -449,6 +449,7 @@ void netdata_cleanup_and_exit(int ret) {
449
error_limit_static_thread_var(erl, 1, 100 * USEC_PER_MS);
450
error_limit(&erl, "waiting for %zu collectors to finish", running);
451
// sleep_usec(100 * USEC_PER_MS);
452
+ cleanup_destroyed_dictionaries();
453
}
454
}
455
libnetdata/dictionary/dictionary.c
+11
-2
@@ -137,6 +137,7 @@ struct dictionary {
137
const char *creation_function;
138
const char *creation_file;
139
size_t creation_line;
140
+ pid_t creation_tid;
141
#endif
142
143
usec_t last_gc_run_us;
@@ -1873,6 +1874,7 @@ void cleanup_destroyed_dictionaries(void) {
1874
size_t line = dict->creation_line;
1875
const char *file = dict->creation_file;
1876
const char *function = dict->creation_function;
1877
+ pid_t pid = dict->creation_tid;
1878
#endif
1879
1880
DICTIONARY_STATS_DICT_DESTROY_QUEUED_MINUS1(dict);
@@ -1880,13 +1882,19 @@ void cleanup_destroyed_dictionaries(void) {
1882
1883
internal_error(
1884
true,
1883
- "DICTIONARY: freed dictionary with delayed destruction, created from %s() %zu@%s.",
1884
- function, line, file);
1885
+ "DICTIONARY: freed dictionary with delayed destruction, created from %s() %zu@%s pid %d.",
1886
+ function, line, file, pid);
1887
1888
if(last) last->next = next;
1889
else dictionaries_waiting_to_be_destroyed = next;
1890
}
1891
else {
1892
+
1893
+ internal_error(
1894
+ true,
1895
+ "DICTIONARY: cannot free dictionary with delayed destruction, created from %s() %zu@%s pid %d.",
1896
+ function, line, file, pid);
1897
+
1898
DICTIONARY_STATS_DICT_DESTROY_QUEUED_PLUS1(dict);
1899
last = dict;
1900
}
@@ -2085,6 +2093,7 @@ DICTIONARY *dictionary_create_view(DICTIONARY *master) {
2093
dict->creation_function = function;
2094
dict->creation_file = file;
2095
dict->creation_line = line;
2096
+ dict->creation_tid = gettid();
2097
#endif
2098
2099
DICTIONARY_STATS_DICT_CREATIONS_PLUS1(dict);
libnetdata/dictionary/dictionary.h
+2
@@ -162,6 +162,8 @@ void dictionary_version_increment(DICTIONARY *dict);
162
163
void dictionary_garbage_collect(DICTIONARY *dict);
164
165
+void cleanup_destroyed_dictionaries(void);
166
+
167
// ----------------------------------------------------------------------------
168
// Set an item in the dictionary
169
//