aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-10-20 14:44:53 +0200
committerGitHub <[email protected]>2023-10-20 14:44:53 +0200
commit9a1425265a1d518aaf87cde01f9aef741a609b2d (patch)
treeff6f4cabdb59cec3509ba1ccabe3afbb461c0f48
parentplace tests in own group (for sln) (#488) (diff)
downloadzen-9a1425265a1d518aaf87cde01f9aef741a609b2d.tar.xz
zen-9a1425265a1d518aaf87cde01f9aef741a609b2d.zip
improve error handling when parsing http requests (#489)
* catch exceptions in HttpRequestParser::OnMessageComplete() callback
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/zenhttp/servers/httpparser.cpp42
2 files changed, 37 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87f7417b0..08229e944 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
- Feature: New endpoint `/admin/flush ` to flush all storage - CAS, Cache and ProjectStore
- Feature: New command `zen flush` to flush all storage - CAS, Cache and ProjectStore
- Bugfix: Fix implementation when claiming GC reserve during GC
+- Bugfix: Catch exceptions when processing requests with asio http and log errors
- Improved: Command `zen gc-status` now gives details about storage, when last GC occured, how long until next GC etc
- Changed: Cache access and write log are disabled by default
- Changed: We no longer purge out block location for missing blocks to allow testing/analisys of snapshots of server states without copying full set of data
diff --git a/src/zenhttp/servers/httpparser.cpp b/src/zenhttp/servers/httpparser.cpp
index 6b987151a..c64134c95 100644
--- a/src/zenhttp/servers/httpparser.cpp
+++ b/src/zenhttp/servers/httpparser.cpp
@@ -2,6 +2,7 @@
#include "httpparser.h"
+#include <zencore/except.h>
#include <zencore/logging.h>
#include <zencore/string.h>
@@ -62,7 +63,6 @@ HttpRequestParser::ConsumeData(const char* InputData, size_t DataSize)
ZEN_WARN("HTTP parser error {} ('{}'). Closing connection", http_errno_name(HttpErrno), http_errno_description(HttpErrno));
return ~0ull;
}
-
return ConsumedBytes;
}
@@ -360,11 +360,41 @@ HttpRequestParser::OnMessageBegin()
int
HttpRequestParser::OnMessageComplete()
{
- m_Connection.HandleRequest();
-
- ResetState();
-
- return 0;
+ try
+ {
+ m_Connection.HandleRequest();
+ ResetState();
+ return 0;
+ }
+ catch (std::system_error& SystemError)
+ {
+ if (IsOOM(SystemError.code()))
+ {
+ ZEN_WARN("out of memory when processing http request: '{}'", SystemError.what());
+ }
+ else if (IsOOD(SystemError.code()))
+ {
+ ZEN_WARN("out of disk space when processing http request: '{}'", SystemError.what());
+ }
+ else
+ {
+ ZEN_ERROR("failed processing http request: '{}'", SystemError.what());
+ }
+ ResetState();
+ return 1;
+ }
+ catch (std::bad_alloc& BadAlloc)
+ {
+ ZEN_WARN("out of memory when processing http request: '{}'", BadAlloc.what());
+ ResetState();
+ return 1;
+ }
+ catch (std::exception& Ex)
+ {
+ ZEN_ERROR("failed processing http request: '{}'", Ex.what());
+ ResetState();
+ return 1;
+ }
}
} // namespace zen