cluster/OnLoop: Fix coverity report about proc accessed without lock

Coverity complains proc is set under a lock, but accessed in Process()
without a lock. Fix this by setting it in Close() also without locking.
The proc member should only ever be accessed my the main thread.
This commit is contained in:
Arne Welzel 2025-04-28 16:23:06 +02:00
parent b9b268bd86
commit 4101efed4f

View file

@ -81,8 +81,16 @@ public:
* Close the IO source. * Close the IO source.
*/ */
void Close() { void Close() {
if ( std::this_thread::get_id() != main_thread_id ) {
fprintf(stderr, "OnLoopProcess::Close() not called by main thread!");
abort();
}
zeek::iosource_mgr->UnregisterFd(flare.FD(), this); zeek::iosource_mgr->UnregisterFd(flare.FD(), this);
// Ensure Process() is short-circuited from now on.
proc = nullptr;
{ {
// Close under lock to guarantee visibility for // Close under lock to guarantee visibility for
// any pending queuers QueueForProcessing() calls. // any pending queuers QueueForProcessing() calls.
@ -91,9 +99,6 @@ public:
// Wake a process stuck in queueing. // Wake a process stuck in queueing.
cond.notify_one(); cond.notify_one();
// Don't attempt to Process anymore.
proc = nullptr;
} }
// Wait for any active queuers to vanish, should be quick. // Wait for any active queuers to vanish, should be quick.