-
Type:
Problem report
-
Resolution: Unresolved
-
Priority:
Major
-
Affects Version/s: 8.0.0
-
Component/s: Server (S)
-
Support backlog
Should enable keepalive and timeout in clickhouse and elasticsearch to avoid hang when connection no longer responds.
diff --git a/src/libs/zbxhistory/history_clickhouse.c b/src/libs/zbxhistory/history_clickhouse.c index 18eae433edf..cd7d83d84b7 100644 --- a/src/libs/zbxhistory/history_clickhouse.c +++ b/src/libs/zbxhistory/history_clickhouse.c @@ -333,6 +333,9 @@ static void history_clickhouse_close(void *data) ******************************************************************************/ static int history_clickhouse_conn_init(zbx_clickhouse_conn_t *conn, zbx_clickhouse_data_t *d, char **error) { +#define ZBX_CURLOPT_TIMEOUT 3600L +#define ZBX_CURLOPT_TCP_KEEPIDLE 120L +#define ZBX_CURLOPT_TCP_KEEPINTVL 60L CURLoption opt; CURLcode err; int ret = FAIL; @@ -349,7 +352,13 @@ static int history_clickhouse_conn_init(zbx_clickhouse_conn_t *conn, zbx_clickho CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_WRITEDATA, &conn->resp.page)) || CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_ERRORBUFFER, conn->resp.errbuf)) || CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_ACCEPT_ENCODING, "")) || - CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_PRIVATE, conn))) + CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_PRIVATE, conn)) || + CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_TIMEOUT, ZBX_CURLOPT_TIMEOUT)) || + CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_TCP_KEEPALIVE, 1L)) || + CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_TCP_KEEPIDLE, + ZBX_CURLOPT_TCP_KEEPIDLE)) || + CURLE_OK != (err = curl_easy_setopt(conn->handle, opt = CURLOPT_TCP_KEEPINTVL, + ZBX_CURLOPT_TCP_KEEPINTVL))) { *error = zbx_dsprintf(NULL, "cannot set curl option %d: %s", (int)opt, curl_easy_strerror(err)); goto fail;