Skip to content

Commit c8e2907

Browse files
committed
fix(userspace/falco): fix outputs_http timeout
libcurl timeout prevent to send alert through http keep trying to send the alert Signed-off-by: Clément Bénier <[email protected]>
1 parent d8c6af8 commit c8e2907

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

falco.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ http_output:
746746
echo: false
747747
compress_uploads: false
748748
keep_alive: false
749+
# Maximum consecutive timeouts of libcurl to ignore
750+
max_consecutive_timeouts: 5
749751

750752
# [Stable] `program_output`
751753
#

userspace/falco/configuration.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ void falco_configuration::load_yaml(const std::string &config_name) {
447447
keep_alive = m_config.get_scalar<bool>("http_output.keep_alive", false);
448448
http_output.options["keep_alive"] = keep_alive ? std::string("true") : std::string("false");
449449

450+
uint32_t max_consecutive_timeouts;
451+
max_consecutive_timeouts =
452+
m_config.get_scalar<uint32_t>("http_output.max_consecutive_timeouts", 5);
453+
http_output.options["max_consecutive_timeouts"] = std::to_string(max_consecutive_timeouts);
454+
450455
m_outputs.push_back(http_output);
451456
}
452457

userspace/falco/outputs_http.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,18 @@ bool falco::outputs::output_http::init(const config &oc,
103103

104104
void falco::outputs::output_http::output(const message *msg) {
105105
CURLcode res = curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, msg->msg.c_str());
106-
CHECK_RES(curl_easy_perform(m_curl));
106+
uint32_t max_consecutive_timeouts =
107+
static_cast<uint32_t>(std::stoi(m_oc.options["max_consecutive_timeouts"]));
108+
uint32_t curl_easy_platform_calls = 0;
109+
110+
if(res == CURLE_OK) {
111+
do {
112+
res = curl_easy_perform(m_curl);
113+
curl_easy_platform_calls++;
114+
} while(res == CURLE_OPERATION_TIMEDOUT &&
115+
curl_easy_platform_calls <= max_consecutive_timeouts);
116+
}
117+
107118
if(res != CURLE_OK) {
108119
falco_logger::log(
109120
falco_logger::level::ERR,

0 commit comments

Comments
 (0)