From 9cb14157b470228d562e3ce3335cc991850f5fdd Mon Sep 17 00:00:00 2001 From: adiholden Date: Sun, 27 Aug 2023 13:48:41 +0300 Subject: [PATCH] fix(server): rdb loader catch bad alloc (#1748) While loading rdb snapshot, if oom is reached a bad alloc exception is thrown. Now we catch it and write warning to log and fali loader. Signed-off-by: adi_holden --- src/server/rdb_load.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/server/rdb_load.cc b/src/server/rdb_load.cc index 4bedf042e751..b9bf27f0c265 100644 --- a/src/server/rdb_load.cc +++ b/src/server/rdb_load.cc @@ -2268,9 +2268,16 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) { if (item->expire_ms > 0 && db_cntx.time_now_ms >= item->expire_ms) continue; - auto [it, added] = db_slice.AddOrUpdate(db_cntx, item->key, std::move(pv), item->expire_ms); - if (!added) { - LOG(WARNING) << "RDB has duplicated key '" << item->key << "' in DB " << db_ind; + try { + auto [it, added] = db_slice.AddOrUpdate(db_cntx, item->key, std::move(pv), item->expire_ms); + if (!added) { + LOG(WARNING) << "RDB has duplicated key '" << item->key << "' in DB " << db_ind; + } + } catch (const std::bad_alloc&) { + LOG(ERROR) << "OOM failed to add key '" << item->key << "' in DB " << db_ind; + ec_ = RdbError(errc::out_of_memory); + stop_early_ = true; + break; } }