@cryptotaxi247 / netdata-1 / commits / 4ee1eb54a

Improve ACLK connection handling (#20625)

* Caller will do the cleanup * Immediate cleanup on failure * Set proxy right before using it to avoid memory leaks on other failures * Fix incorrect transport index in URL parsing for ACLK environment * Code cleanup

Stelios Fragkakis committed Jul 7, 2025 at 15:53 UTC 4ee1eb54af8cbd8c96a2125ef28f01bc5f8d8313
2 files changed +8 -6
src/aclk/aclk.c
+8 -5
@@ -645,9 +645,6 @@ static int aclk_attempt_to_connect(mqtt_wss_client client)
645 continue;
646 }
647
648 - struct mqtt_wss_proxy proxy_conf = { .host = NULL, .port = 0, .username = NULL, .password = NULL, .type = MQTT_WSS_DIRECT };
649 - aclk_set_proxy((char**)&proxy_conf.host, &proxy_conf.port, (char**)&proxy_conf.username, (char**)&proxy_conf.password, &proxy_conf.type);
650 -
648 struct mqtt_connect_params mqtt_conn_params = {
649 .clientid = "anon",
650 .username = "anon",
@@ -670,6 +667,9 @@ static int aclk_attempt_to_connect(mqtt_wss_client client)
667 url_t_destroy(&base_url);
668 if (rc != HTTPS_CLIENT_RESP_OK) {
669 aclk_status_set((ACLK_STATUS)rc);
670 + aclk_env_t_destroy(aclk_env);
671 + freez(aclk_env);
672 + aclk_env = NULL;
673 continue;
674 }
675
@@ -728,9 +728,9 @@ static int aclk_attempt_to_connect(mqtt_wss_client client)
728 }
729
730 memset(&mqtt_url, 0, sizeof(url_t));
731 - if (url_parse(aclk_env->transports[rc]->endpoint, &mqtt_url)){
731 + if (url_parse(aclk_env->transports[trp]->endpoint, &mqtt_url)){
732 aclk_status_set(ACLK_STATUS_INVALID_ENV_TRANSPORT_URL);
733 - error_report("ACLK: failed to parse target URL for /env trp idx %d \"%s\"", trp, aclk_env->transports[rc]->endpoint);
733 + error_report("ACLK: failed to parse target URL for /env trp idx %d \"%s\"", trp, aclk_env->transports[trp]->endpoint);
734 url_t_destroy(&mqtt_url);
735 continue;
736 }
@@ -744,6 +744,9 @@ static int aclk_attempt_to_connect(mqtt_wss_client client)
744
745 int ssl_flags = cloud_config_insecure_get() ? MQTT_WSS_SSL_ALLOW_SELF_SIGNED : MQTT_WSS_SSL_CERT_CHECK_FULL;
746
747 + struct mqtt_wss_proxy proxy_conf = { .host = NULL, .port = 0, .username = NULL, .password = NULL, .type = MQTT_WSS_DIRECT };
748 + aclk_set_proxy((char**)&proxy_conf.host, &proxy_conf.port, (char**)&proxy_conf.username, (char**)&proxy_conf.password, &proxy_conf.type);
749 +
750 #ifdef ACLK_DISABLE_CHALLENGE
751 int mqtt_rc = mqtt_wss_connect(client, base_url.host, base_url.port, &mqtt_conn_params, ssl_flags, &proxy_conf);
752 url_t_destroy(&base_url);
src/aclk/aclk_otp.c
-1
@@ -790,7 +790,6 @@ static int parse_json_env(const char *json_str, aclk_env_t *env) {
790 return 0;
791
792 exit:
793 - aclk_env_t_destroy(env);
793 json_object_put(json);
794 return 1;
795 }