From 355922a9b5814f5deea86a1443a084a07f597751 Mon Sep 17 00:00:00 2001 From: David Hale Date: Tue, 25 Aug 2026 18:09:25 -0700 Subject: [PATCH 1/2] fixes bug where a null db pointer exception wasn't caught --- utils/database.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/utils/database.cpp b/utils/database.cpp index 14e5f42d..d020756c 100644 --- a/utils/database.cpp +++ b/utils/database.cpp @@ -77,6 +77,7 @@ namespace Database { */ bool SessionPool::_test_session(std::shared_ptr db) { // pass-fail + if ( !db ) return false; try { db->sql("SELECT 1").execute(); return true; // it either works, @@ -104,6 +105,7 @@ namespace Database { // make a new session if this one is bad if (!_test_session(db)) db = _create_session(); + if ( !db ) throw std::runtime_error( "failed to obtain a valid database connection" ); return db; } @@ -117,11 +119,17 @@ namespace Database { * */ void SessionPool::_return_session(std::shared_ptr db) { - { - std::lock_guard lock(_mtx); - _queue.push(db); + // never let an exception escape -- this is called from ~SessionGuard(), + // which is implicitly noexcept + try { + { + std::lock_guard lock( _mtx ); + _queue.push( db ); + } + _cv.notify_one(); + } + catch ( ... ) { } - _cv.notify_one(); } /***** SessionPool::_return_session *****************************************/ From a668b4883ae39afffc72f568213b23c4a24f989d Mon Sep 17 00:00:00 2001 From: David Hale Date: Tue, 25 Aug 2026 18:21:48 -0700 Subject: [PATCH 2/2] this should fix it at the source, don't put a null db in the pool --- utils/database.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/database.cpp b/utils/database.cpp index d020756c..adb9e585 100644 --- a/utils/database.cpp +++ b/utils/database.cpp @@ -19,7 +19,10 @@ namespace Database { SessionPool::SessionPool(const std::string &host, int port, const std::string &user, const std::string &pass): _dbhost(host), _dbport(port), _dbuser(user), _dbpass(pass) { // create the pool of sessions - for (int i = 0; i < DBPOOLSIZE; ++i) { _queue.push(_create_session()); } + for (int i = 0; i < DBPOOLSIZE; ++i) { + auto db = _create_session(); + if (db) _queue.push(db); + } } /***** SessionPool::SessionPool *********************************************/ @@ -39,6 +42,7 @@ namespace Database { while (!_queue.empty()) { auto db = _queue.front(); _queue.pop(); + if (!db) continue; try { db->close(); } catch (...) { } }