aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-09-19 05:03:54 -0400
committerGitHub <[email protected]>2023-09-19 11:03:54 +0200
commit0da54c8f3ad4aa6d2f3e9eac3ff1a77f07d19fb7 (patch)
tree6946629458686541a5913888583157388984e620
parentadd DiskWriteBlocker to structured cache store log writer (#408) (diff)
downloadzen-0da54c8f3ad4aa6d2f3e9eac3ff1a77f07d19fb7.tar.xz
zen-0da54c8f3ad4aa6d2f3e9eac3ff1a77f07d19fb7.zip
handle errors in spdlog gracefully (#410)
* handle errors in spdlog gracefully - try to report and avoid termination * changelog
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/zenserver/diag/logging.cpp29
2 files changed, 31 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 505ca9f3b..76abe8640 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,6 @@
##
+- Improvement: Ignore OOM errors in spdlog, just drop the error since we can't do anything useful if we run out of memory here
+- Improvement: Try to catch any exceptions in spdlog error handling to avoid abort termination of process
- Improvement: Block cache access/write log from writing to log if disk is low on free space
## 0.2.22
diff --git a/src/zenserver/diag/logging.cpp b/src/zenserver/diag/logging.cpp
index 13270b41d..0f15253cc 100644
--- a/src/zenserver/diag/logging.cpp
+++ b/src/zenserver/diag/logging.cpp
@@ -446,6 +446,35 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
FileSink->set_pattern("[%C-%m-%d.%e %T] [%n] [%l] %v");
}
+ spdlog::set_error_handler([](const std::string& msg) {
+ if (msg == std::bad_alloc().what())
+ {
+ // Don't report out of memory in spdlog as we usually log in response to errors which will cause another OOM crashing the
+ // program
+ return;
+ }
+ // Bypass zen logging wrapping to reduce potential other error sources
+ if (auto ErrLogger = zen::logging::ErrorLog(); ErrLogger != nullptr)
+ {
+ try
+ {
+ ErrLogger->log(spdlog::level::err, msg);
+ }
+ catch (const std::exception&)
+ {
+ // Just ignore any errors when in error handler
+ }
+ }
+ try
+ {
+ Log().error(msg);
+ }
+ catch (const std::exception&)
+ {
+ // Just ignore any errors when in error handler
+ }
+ });
+
const std::string StartLogTime = zen::DateTime::Now().ToIso8601();
const zen::Oid ServerSessionId = zen::GetSessionId();