Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1614903193, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"ea7ccf44d231f1891a05bd719bdc5800", "commit": {"type":"commit", "time": 1589228461, "time_ofs": 60, "oid_tree": { "oid": "dae693e6b3419ffd09b4c841dd2dda3734ac56d6", "alias": []}, "oid":{ "oid": "c97b68272c6c473bf7f2712da0f3fb870c3c92e0", "alias": []}, "msg": "connect: enforce timeout for connect async wait", "sig_commit": { "git_time": { "time": 1589228461, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1589184465, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "connect: enforce timeout for connect async wait\n\nThis patch allows client connections to recover from a nonresponsive\n(ie, does not complete connect()) peer and continue to try subsequent\nDNS results." , "diff": "diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h\nindex 811e4ef..652d983 100644\n--- a/lib/core-net/private-lib-core-net.h\n+++ b/lib/core-net/private-lib-core-net.h\n@@ -680,6 +680,7 @@ struct lws {\n \tlws_sorted_usec_list_t\t\tsul_timeout;\n \tlws_sorted_usec_list_t\t\tsul_hrtimer;\n \tlws_sorted_usec_list_t\t\tsul_validity;\n+\tlws_sorted_usec_list_t\t\tsul_connect_timeout;\n \n \tstruct lws_dll2\t\t\tdll_buflist; /* guys with pending rxflow */\n \tstruct lws_dll2\t\t\tsame_vh_protocol;\ndiff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c\nindex c90abea..5a4370d 100644\n--- a/lib/roles/http/client/client-handshake.c\n+++ b/lib/roles/http/client/client-handshake.c\n@@ -346,6 +346,20 @@ failed:\n \treturn NULL;\n }\n \n+static void\n+lws_client_conn_wait_timeout(lws_sorted_usec_list_t *sul)\n+{\n+\tstruct lws *wsi \u003d lws_container_of(sul, struct lws, sul_connect_timeout);\n+\n+\t/*\n+\t * This is used to constrain the time we're willing to wait for a\n+\t * connection before giving up on it and retrying.\n+\t */\n+\n+\tlwsl_info(\u0022%s: connect wait timeout has fired\u005cn\u0022, __func__);\n+\tlws_client_connect_3_connect(wsi, NULL, NULL, 0, NULL);\n+}\n+\n struct lws *\n lws_client_connect_3_connect(struct lws *wsi, const char *ads,\n \t\t\t const struct addrinfo *result, int n, void *opaque)\n@@ -392,6 +406,9 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,\n \t\tsocklen_t sl \u003d sizeof(int);\n \t\tint e \u003d 0;\n \n+\t\tif (!result \u0026\u0026 !wsi-\u003esul_connect_timeout.list.owner)\n+\t\t\tgoto connect_to;\n+\n \t\t/*\n \t\t* this resets SO_ERROR after reading it. If there's an error\n \t\t* condition the connect definitively failed.\n@@ -668,6 +685,9 @@ ads_known:\n \t\twsi-\u003edetlat.earliest_write_req_pre_write \u003d lws_now_usecs();\n #endif\n \n+\tif (!result \u0026\u0026 !wsi-\u003esul_connect_timeout.list.owner)\n+\t\tgoto connect_to;\n+\n \tm \u003d connect(wsi-\u003edesc.sockfd, (const struct sockaddr *)psa, n);\n \tif (m \u003d\u003d -1) {\n \t\tint errno_copy \u003d LWS_ERRNO;\n@@ -699,6 +719,15 @@ ads_known:\n #endif\n \n \t\t/*\n+\t\t * Let's set a specialized timeout for the connect completion,\n+\t\t * it uses wsi-\u003esul_connect_timeout just for this purpose\n+\t\t */\n+\n+\t\tlws_sul_schedule(wsi-\u003econtext, 0, \u0026wsi-\u003esul_connect_timeout,\n+\t\t\t\t lws_client_conn_wait_timeout,\n+\t\t\t\t wsi-\u003econtext-\u003etimeout_secs * LWS_USEC_PER_SEC);\n+\n+\t\t/*\n \t\t * must do specifically a POLLOUT poll to hear\n \t\t * about the connect completion\n \t\t */\n@@ -709,7 +738,8 @@ ads_known:\n \t}\n \n conn_good:\n-\n+\tlws_sul_schedule(wsi-\u003econtext, 0, \u0026wsi-\u003esul_connect_timeout, NULL,\n+\t\t\t LWS_SET_TIMER_USEC_CANCEL);\n \tlwsl_info(\u0022%s: Connection started %p\u005cn\u0022, __func__, wsi-\u003edns_results);\n \n \t/* the tcp connection has happend */\n@@ -773,6 +803,12 @@ oom4:\n \treturn NULL;\n \n \n+connect_to:\n+\t/*\n+\t * It looks like the sul_connect_timeout fired\n+\t */\n+\tlwsl_info(\u0022%s: abandoning connect due to timeout\u005cn\u0022, __func__);\n+\n try_next_result_fds:\n \t__remove_wsi_socket_from_fds(wsi);\n \n@@ -784,6 +820,8 @@ try_next_result_closesock:\n \twsi-\u003edesc.sockfd \u003d LWS_SOCK_INVALID;\n \n try_next_result:\n+\tlws_sul_schedule(wsi-\u003econtext, 0, \u0026wsi-\u003esul_connect_timeout,\n+\t\t\t NULL, LWS_SET_TIMER_USEC_CANCEL);\n \tif (wsi-\u003edns_results_next) {\n \t\twsi-\u003edns_results_next \u003d wsi-\u003edns_results_next-\u003eai_next;\n \t\tif (wsi-\u003edns_results_next)\n","s":{"c":1614903193,"u": 2732}} ],"g": 3297,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}