From 16c745cee433f81ab9b7b2062a829dea34e7127d Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 5 Feb 2025 13:43:02 +0100 Subject: [PATCH] cluster/zeromq: Do not call util::fmt() from thread ...util::fmt() uses a static buffer, so this is problematic. I've dabbled a bit replacing std::thread with using threading::BasicThread which would offer Fmt(), but this makes things more complicated. Primarily as BasicThread is registered with the thread manager and the shutdown interactions become entangled. The thread might be terminated before the backend, or vice-versa. Seems nicer for the thread to be owned by the backend. --- src/cluster/backend/zeromq/ZeroMQ.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cluster/backend/zeromq/ZeroMQ.cc b/src/cluster/backend/zeromq/ZeroMQ.cc index ef117749ac..66e0b2fd9e 100644 --- a/src/cluster/backend/zeromq/ZeroMQ.cc +++ b/src/cluster/backend/zeromq/ZeroMQ.cc @@ -356,7 +356,9 @@ bool ZeroMQBackend::DoPublishLogWrites(const logging::detail::LogWriteHeader& he } void ZeroMQBackend::Run() { - util::detail::set_thread_name(zeek::util::fmt("zmq-%p", this)); + char name[4 + 2 + 16 + 1]{}; // zmq-0x<8byte pointer in hex> + snprintf(name, sizeof(name), "zmq-%p", this); + util::detail::set_thread_name(name); ZEROMQ_DEBUG_THREAD_PRINTF(DebugFlag::THREAD, "Thread starting (%p)\n", this); using MultipartMessage = std::vector;