cluster/zeromq: Call DoTerminate() in destructor

Normal life-cycle is that Terminate() / DoTerminate() is called
by zeek-setup code. If that doesn't happen, shutdown and join
threads during destructor.

try { } catch (...) suggested by Benjamin.
This commit is contained in:
Arne Welzel 2025-02-05 15:25:08 +01:00
parent 2c6d934ef4
commit 6008e67008
2 changed files with 16 additions and 0 deletions

View file

@ -66,6 +66,16 @@ ZeroMQBackend::ZeroMQBackend(std::unique_ptr<EventSerializer> es, std::unique_pt
main_inproc = zmq::socket_t(ctx, zmq::socket_type::pair); main_inproc = zmq::socket_t(ctx, zmq::socket_type::pair);
} }
ZeroMQBackend::~ZeroMQBackend() {
try {
// DoTerminate is idempotent.
DoTerminate();
} catch ( ... ) {
// This should never happen.
abort();
}
}
void ZeroMQBackend::DoInitPostScript() { void ZeroMQBackend::DoInitPostScript() {
ThreadedBackend::DoInitPostScript(); ThreadedBackend::DoInitPostScript();
@ -109,6 +119,7 @@ void ZeroMQBackend::DoTerminate() {
if ( proxy_thread ) { if ( proxy_thread ) {
ZEROMQ_DEBUG("Shutting down proxy thread"); ZEROMQ_DEBUG("Shutting down proxy thread");
proxy_thread->Shutdown(); proxy_thread->Shutdown();
proxy_thread.reset();
} }
ZEROMQ_DEBUG("Terminated"); ZEROMQ_DEBUG("Terminated");

View file

@ -20,6 +20,11 @@ public:
ZeroMQBackend(std::unique_ptr<EventSerializer> es, std::unique_ptr<LogSerializer> ls, ZeroMQBackend(std::unique_ptr<EventSerializer> es, std::unique_ptr<LogSerializer> ls,
std::unique_ptr<detail::EventHandlingStrategy> ehs); std::unique_ptr<detail::EventHandlingStrategy> ehs);
/**
* Destructor.
*/
~ZeroMQBackend();
/** /**
* Spawns a thread running zmq_proxy() for the configured XPUB/XSUB listen * Spawns a thread running zmq_proxy() for the configured XPUB/XSUB listen
* sockets. Only one node in a cluster should do this. * sockets. Only one node in a cluster should do this.