From ece2aa52c029dce7141bb6cb0ca4304e74ce23a6 Mon Sep 17 00:00:00 2001 From: Qi Luo Date: Wed, 26 Nov 2025 01:57:33 +0000 Subject: [PATCH 1/2] Ensure RedisPipeline dtor not to throw --- common/redispipeline.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/redispipeline.h b/common/redispipeline.h index 96f97ab8b..1bbbe1ce0 100644 --- a/common/redispipeline.h +++ b/common/redispipeline.h @@ -36,7 +36,18 @@ class RedisPipeline { if (m_ownerTid == gettid()) { // call flush from different thread will trigger race condition issue. - flush(); + try + { + flush(); + } + catch (const std::exception& e) + { + SWSS_LOG_ERROR("Exception during RedisPipeline flush in destructor: %s, Database: %s", e.what(), getDbName().c_str()); + } + catch (...) + { + SWSS_LOG_ERROR("Unknown exception during RedisPipeline flush in destructor, Database: %s", getDbName().c_str()); + } } else { From 4b26e520402ee5dac4acc6282d6be2df5ccfb518 Mon Sep 17 00:00:00 2001 From: Qi Luo Date: Wed, 26 Nov 2025 07:02:32 +0000 Subject: [PATCH 2/2] Strict noexcept --- common/redispipeline.h | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/common/redispipeline.h b/common/redispipeline.h index 1bbbe1ce0..95df2758f 100644 --- a/common/redispipeline.h +++ b/common/redispipeline.h @@ -32,29 +32,38 @@ class RedisPipeline { lastHeartBeat = std::chrono::steady_clock::now(); } - ~RedisPipeline() { - if (m_ownerTid == gettid()) + ~RedisPipeline() noexcept { + try { - // call flush from different thread will trigger race condition issue. - try + std::string dbName = getDbName(); + + if (m_ownerTid == gettid()) { - flush(); - } - catch (const std::exception& e) - { - SWSS_LOG_ERROR("Exception during RedisPipeline flush in destructor: %s, Database: %s", e.what(), getDbName().c_str()); + // call flush from different thread will trigger race condition issue. + try + { + flush(); + } + catch (const std::exception& e) + { + SWSS_LOG_ERROR("Exception during RedisPipeline flush in destructor: %s, Database: %s", e.what(), dbName.c_str()); + } } - catch (...) + else { - SWSS_LOG_ERROR("Unknown exception during RedisPipeline flush in destructor, Database: %s", getDbName().c_str()); + SWSS_LOG_NOTICE("RedisPipeline dtor is called from another thread, possibly due to exit(), Database: %s", dbName.c_str()); } + + delete m_db; } - else + catch (const std::exception& e) { - SWSS_LOG_NOTICE("RedisPipeline dtor is called from another thread, possibly due to exit(), Database: %s", getDbName().c_str()); + fprintf(stderr, "Exception during RedisPipeline destructor: %s\n", e.what()); + } + catch (...) + { + fprintf(stderr, "Unknown exception during RedisPipeline destructor\n"); } - - delete m_db; } redisReply *push(const RedisCommand& command, int expectedType)