threading/Manager: Warn if threads are added after termination

The core.file-analyzer-violation test showed that it's possible to
create new threads (log writers) when Zeek is in the process of
terminating. This can result in the IO manager's deconstructor
deleting IO sources for threads that are still running.

This is sort of a scripting issue, so for now log a reporter warning
when it happens to have a bit of a bread-crumb what might be
going on. In the future it might make sense to plug APIs with
zeek_is_terminating().
This commit is contained in:
Arne Welzel 2024-07-02 12:12:15 +02:00
parent 739a8ac509
commit f050d96503
5 changed files with 27 additions and 0 deletions

View file

@ -28,6 +28,7 @@ Manager::Manager() {
did_process = true;
next_beat = 0;
terminating = false;
terminated = false;
}
Manager::~Manager() {
@ -61,10 +62,18 @@ void Manager::Terminate() {
all_threads.clear();
msg_threads.clear();
terminating = false;
terminated = true;
}
void Manager::AddThread(BasicThread* thread) {
DBG_LOG(DBG_THREADING, "Adding thread %s ...", thread->Name());
// This can happen when log writers or other threads are
// created during the shutdown phase and results in unclean
// shutdowns.
if ( terminated )
reporter->Warning("Thread %s added after threading manager terminated", thread->Name());
all_threads.push_back(thread);
if ( ! heartbeat_timer_running )