From 12e5623fe6ea7ade4e04b22e209b0f3ab4029028 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 19 Jun 2025 23:56:26 -0500 Subject: [PATCH] [ox/logconn] Add exception handling for logger thread --- deps/ox/src/ox/logconn/logconn.cpp | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/deps/ox/src/ox/logconn/logconn.cpp b/deps/ox/src/ox/logconn/logconn.cpp index f027dabd..d101e618 100644 --- a/deps/ox/src/ox/logconn/logconn.cpp +++ b/deps/ox/src/ox/logconn/logconn.cpp @@ -91,23 +91,28 @@ ox::Error LoggerConn::sendInit(const InitTraceMsg &msg) noexcept { } void LoggerConn::msgSend() noexcept { - while (true) { - std::unique_lock lk(m_waitMut); - m_waitCond.wait(lk); - if (!m_running) { - break; - } - std::lock_guard const buffLk(m_buffMut); + try { while (true) { - Array tmp; - const auto read = m_buff.read(tmp.data(), tmp.size()); - if (!read) { + std::unique_lock lk(m_waitMut); + m_waitCond.wait(lk); + if (!m_running) { break; } - oxAssert(read <= tmp.size(), "logger trying to read too much data"); - //std::printf("LoggerConn: sending %lu bytes\n", read); - std::ignore = send(tmp.data(), read); + std::lock_guard const buffLk(m_buffMut); + while (true) { + Array tmp; + const auto read = m_buff.read(tmp.data(), tmp.size()); + if (!read) { + break; + } + oxAssert(read <= tmp.size(), "logger trying to read too much data"); + //std::printf("LoggerConn: sending %lu bytes\n", read); + std::ignore = send(tmp.data(), read); + } } + } catch (std::exception const &e) { + oxErrf("Exception in logger thread: {}\n", e.what()); + oxAssert(false, "logger thread exception"); } }