Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(libsinsp): Don't loop forever on container api #1354

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ bool docker_async_source::parse(const docker_lookup_request& request, sinsp_cont
}
/* FALLTHRU */
case docker_connection::docker_response::RESP_ERROR:
case docker_connection::docker_response::RESP_TIMEOUT:
g_logger.format(sinsp_logger::SEV_DEBUG,
"docker_async (%s): Url fetch failed, returning false",
request.container_id.c_str());
Expand Down
3 changes: 2 additions & 1 deletion userspace/libsinsp/container_engine/docker/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class docker_connection {
enum docker_response {
RESP_OK = 0,
RESP_BAD_REQUEST = 1,
RESP_ERROR = 2
RESP_ERROR = 2,
RESP_TIMEOUT = 3
};

docker_connection();
Expand Down
17 changes: 17 additions & 0 deletions userspace/libsinsp/container_engine/docker/connection_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
#include "sinsp_int.h"

namespace {
const uint32_t max_allowed_timeouts = 5;

size_t docker_curl_write_callback(const char *ptr, size_t size, size_t nmemb, std::string *json)
{
Expand Down Expand Up @@ -107,6 +108,7 @@ docker_connection::docker_response docker_connection::get_docker(const docker_lo
return docker_response::RESP_ERROR;
}

uint32_t num_timeouts = 0;
while(true)
{
int still_running;
Expand Down Expand Up @@ -141,6 +143,21 @@ docker_connection::docker_response docker_connection::get_docker(const docker_lo
ASSERT(false);
return docker_response::RESP_ERROR;
}
if(numfds == 0)
{
// Operation timed out
if(++num_timeouts >= max_allowed_timeouts)
{
g_logger.format(sinsp_logger::SEV_WARNING,
"docker_async (%s): Max timeouts exceeded",
url.c_str());
return docker_response::RESP_TIMEOUT;
}
g_logger.format(sinsp_logger::SEV_DEBUG,
"docker_async (%s): Operation timed out %d times",
url.c_str(),
num_timeouts);
}
}

if(curl_multi_remove_handle(m_curlm, curl) != CURLM_OK)
Expand Down
Loading