fix: resolve Event::Run thread hang preventing zmc clean shutdown

Event::Run could block indefinitely in PacketQueue methods during normal
event closing (closeEvent from analysis thread), because their wait
predicates only check deleting/zm_terminate, not Event's terminate_ flag.

Three changes fix this:
- get_packet_no_wait: return immediately when iterator at end instead of
  blocking on condition variable (makes it truly non-blocking)
- Event::Run: use increment_it(wait=false) since deletePacket can advance
  the iterator to end() during AddPacket_ without the queue lock
- Event::Stop: call packetqueue->notify_all() to wake timed waits so
  Run() checks terminate_ promptly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Isaac Connor
2026-02-12 23:00:59 -05:00
parent 7b71ad2149
commit 0882a3ad1e
4 changed files with 19 additions and 19 deletions

View File

@@ -475,11 +475,8 @@ ZMPacketLock PacketQueue::get_packet_no_wait(packetqueue_iterator *it) {
std::addressof(*it), (*it == pktQueue.end()));
if (deleting or zm_terminate)
return ZMPacketLock();
if ((*it == pktQueue.end()) and !(deleting or zm_terminate)) {
Debug(2, "waiting. Queue size %zu it == end? %d", pktQueue.size(), (*it == pktQueue.end()));
condition.wait(lck, [&]{ return (*it != pktQueue.end()) || deleting || zm_terminate; });
}
if ((*it == pktQueue.end()) or deleting or zm_terminate) return ZMPacketLock();
if (*it == pktQueue.end())
return ZMPacketLock();
std::shared_ptr<ZMPacket> p = *(*it);
ZMPacketLock packet_lock(p);