From 1afd497c0cdc876aea6dc70a35d260e609ed2c97 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 20 Jun 2025 15:22:25 +0200 Subject: [PATCH] cluster/zeromq: Short-circuit DoPublishLogWrite() when not initialized After moving the log_push initialization from the constructor to the DoInit() method, it's now possible that DoPublishLogWrites() is invoked even if DoInit() was never called. Handle this by short-circuiting. This is sort of an error, but can happen during tests if scripts are loaded somewhat arbitrarily. --- src/cluster/backend/zeromq/ZeroMQ.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cluster/backend/zeromq/ZeroMQ.cc b/src/cluster/backend/zeromq/ZeroMQ.cc index 4793e81ac9..e167e97aae 100644 --- a/src/cluster/backend/zeromq/ZeroMQ.cc +++ b/src/cluster/backend/zeromq/ZeroMQ.cc @@ -373,7 +373,6 @@ bool ZeroMQBackend::DoUnsubscribe(const std::string& topic_prefix) { bool ZeroMQBackend::DoPublishLogWrites(const logging::detail::LogWriteHeader& header, const std::string& format, byte_buffer& buf) { - ZEROMQ_DEBUG("Publishing %zu bytes of log writes (path %s)", buf.size(), header.path.c_str()); static std::string message_type = "log-write"; // Publishing a log write is done using 4 parts @@ -389,6 +388,14 @@ bool ZeroMQBackend::DoPublishLogWrites(const logging::detail::LogWriteHeader& he zmq::const_buffer{buf.data(), buf.size()}, }; + // If the log_push socket isn't yet initialized or has been closed, just return. + if ( ! log_push ) { + ZEROMQ_DEBUG("Skipping log write - log_push socket not open"); + return false; + } + + ZEROMQ_DEBUG("Publishing %zu bytes of log writes (path %s)", buf.size(), header.path.c_str()); + for ( size_t i = 0; i < parts.size(); i++ ) { zmq::send_flags flags = zmq::send_flags::dontwait; if ( i < parts.size() - 1 )