summaryrefslogtreecommitdiff
path: root/http/http_connection.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2021-12-07 01:36:06 +0300
committerEd Tanous <ed@tanous.net>2021-12-15 23:20:18 +0300
commit6fbdbcabc3ae43dc372459c6c5ae4d53657267f5 (patch)
treedc56b727976fcfe3ae4a3b938ccd6632032a6279 /http/http_connection.hpp
parent88e1612b4141e9011a70fcb95c76238112051e62 (diff)
downloadbmcweb-6fbdbcabc3ae43dc372459c6c5ae4d53657267f5.tar.xz
Implement connection limit
Now that we rely on normal steady_timer, bmcweb doesn't limit http connections. This commit moves the connectionCount variable out of the debug ifdefs, and into the "normal" build. Then additionally, add a check to ensure that less than 100 connections are started at a time. This count is intended to match the code in timer_queue.hpp that limited this to 100 timers at a given time. Tested: /redfish/v1 returns properly. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I93ceaf8319d09d911b36cb7b21bba0cf64a9f7b8
Diffstat (limited to 'http/http_connection.hpp')
-rw-r--r--http/http_connection.hpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index bfd641154e..06bb63af04 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -35,9 +35,7 @@ inline void prettyPrintJson(crow::Response& res)
res.addHeader("Content-Type", "text/html;charset=UTF-8");
}
-#ifdef BMCWEB_ENABLE_DEBUG
-static std::atomic<int> connectionCount;
-#endif
+static int connectionCount = 0;
// request body limit size set by the bmcwebHttpReqBodyLimitMb option
constexpr unsigned int httpReqBodyLimit =
@@ -67,22 +65,20 @@ class Connection :
prepareMutualTls();
#endif // BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION
-#ifdef BMCWEB_ENABLE_DEBUG
connectionCount++;
+
BMCWEB_LOG_DEBUG << this << " Connection open, total "
<< connectionCount;
-#endif
}
~Connection()
{
res.setCompleteRequestHandler(nullptr);
cancelDeadlineTimer();
-#ifdef BMCWEB_ENABLE_DEBUG
+
connectionCount--;
BMCWEB_LOG_DEBUG << this << " Connection closed, total "
<< connectionCount;
-#endif
}
void prepareMutualTls()
@@ -277,6 +273,12 @@ class Connection :
void start()
{
+ if (connectionCount >= 100)
+ {
+ BMCWEB_LOG_CRITICAL << this << "Max connection count exceeded.";
+ return;
+ }
+
startDeadline();
// TODO(ed) Abstract this to a more clever class with the idea of an