From 0abf7994e8913c19360a0f0b8527495c0f99de87 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Mon, 2 Oct 2023 12:00:00 +0200 Subject: Handle OOM and OOD more gracefully to not spam Sentry with error reports (#434) - Improvement: Catch Out Of Memory and Out Of Disk exceptions and report back to reqeuster without reporting an error to Sentry - Improvement: If creating bucket fails when storing and item in the structured cache, log a warning and propagate error to requester without reporting an error to Sentry - Improvement: Make an explicit flush of the active block written to in blockstore flush - Improvement: Make sure cache and cas MakeIndexSnapshot does not throw exception on failure which would cause and abnormal termniation at exit --- src/zencore/except.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/zencore/except.cpp') diff --git a/src/zencore/except.cpp b/src/zencore/except.cpp index 65f5ebc62..f98743ea9 100644 --- a/src/zencore/except.cpp +++ b/src/zencore/except.cpp @@ -110,4 +110,62 @@ ThrowOutOfMemory(std::string_view Message) } #endif +#if ZEN_PLATFORM_WINDOWS +bool +IsOOM(const std::system_error& SystemError) +{ + switch (SystemError.code().value()) + { + case ERROR_NOT_ENOUGH_MEMORY: + case ERROR_OUTOFMEMORY: + case ERROR_PAGEFILE_QUOTA_EXCEEDED: + case ERROR_NONPAGED_SYSTEM_RESOURCES: + case ERROR_PAGED_SYSTEM_RESOURCES: + case ERROR_PAGEFILE_QUOTA: + case ERROR_COMMITMENT_LIMIT: + return true; + default: + return false; + } +} +bool +IsOOD(const std::system_error& SystemError) +{ + switch (SystemError.code().value()) + { + case ERROR_HANDLE_DISK_FULL: + case ERROR_DISK_FULL: + case ERROR_DISK_RESOURCES_EXHAUSTED: + case ERROR_DISK_QUOTA_EXCEEDED: + return true; + default: + return false; + } +} +#else +bool +IsOOM(const std::system_error& SystemError) +{ + switch (SystemError.code().value()) + { + case ENOMEM: + return true; + default: + return false; + } +} +bool +IsOOD(const std::system_error& SystemError) +{ + switch (SystemError.code().value()) + { + case ENOSPC: + case EDQUOT: + return true; + default: + return false; + } +} +#endif + } // namespace zen -- cgit v1.2.3