From 1b790dc7419b52108cb9e09ae1224ada0041b793 Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Fri, 15 Jan 2021 16:56:18 +0700
Subject: [PATCH] [*] Check for CONNECTING flag in http request timeout

---
 dap-sdk/net/client/dap_client_http.c | 31 ++++++++++++++++------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/dap-sdk/net/client/dap_client_http.c b/dap-sdk/net/client/dap_client_http.c
index 264e8466e1..c44f94541b 100644
--- a/dap-sdk/net/client/dap_client_http.c
+++ b/dap-sdk/net/client/dap_client_http.c
@@ -126,22 +126,27 @@ static bool s_timer_timeout_check(void * a_arg)
 
     if(dap_events_socket_check_unsafe(l_worker, l_es) ){
         if (!dap_uint128_check_equal(l_es->uuid,l_es_handler->uuid)){
-            // Timer esocket wrong argument, ignore this timeout...
+            log_it(L_DEBUG,"Timer esocket wrong argument, ignore this timeout...");
             DAP_DEL_Z(l_es_handler)
             return false;
         }
-        dap_client_http_pvt_t * l_http_pvt = PVT(l_es);
-        log_it(L_WARNING,"Connection timeout for request http://%s:%u/%s, possible network problems or host is down",
-               l_http_pvt->uplink_addr, l_http_pvt->uplink_port, l_http_pvt->path);
-        if(l_http_pvt->error_callback) {
-            l_http_pvt->error_callback(ETIMEDOUT, l_http_pvt->obj);
-            l_http_pvt->were_callbacks_called = true;
-        }
-        l_http_pvt->is_closed_by_timeout = true;
-        log_it(L_INFO, "Close %s sock %u type %d by timeout",
-               l_es->remote_addr_str ? l_es->remote_addr_str : "", l_es->socket, l_es->type);
-        dap_events_socket_remove_and_delete_unsafe(l_es, true);
-    }
+        if (l_es->flags & DAP_SOCK_CONNECTING ){
+            dap_client_http_pvt_t * l_http_pvt = PVT(l_es);
+            log_it(L_WARNING,"Connecting timeout for request http://%s:%u/%s, possible network problems or host is down",
+                   l_http_pvt->uplink_addr, l_http_pvt->uplink_port, l_http_pvt->path);
+            if(l_http_pvt->error_callback) {
+                l_http_pvt->error_callback(ETIMEDOUT, l_http_pvt->obj);
+                l_http_pvt->were_callbacks_called = true;
+            }
+            l_http_pvt->is_closed_by_timeout = true;
+            log_it(L_INFO, "Close %s sock %u type %d by timeout",
+                   l_es->remote_addr_str ? l_es->remote_addr_str : "", l_es->socket, l_es->type);
+            dap_events_socket_remove_and_delete_unsafe(l_es, true);
+        }else
+            log_it(L_DEBUG,"Socket %d is connected, close check timer", l_es->socket);
+    }else
+        log_it(L_DEBUG,"Esocket %p is finished, close check timer", l_es);
+
     DAP_DEL_Z(l_es_handler)
     return false;
 }
-- 
GitLab