diff --git a/lib/core-net/close.c b/lib/core-net/close.c index a4a907904..1c86067b9 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -207,9 +207,10 @@ lws_inform_client_conn_fail(struct lws *wsi, void *arg, size_t len) if (!wsi->protocol) return; - wsi->protocol->callback(wsi, - LWS_CALLBACK_CLIENT_CONNECTION_ERROR, - wsi->user_space, arg, len); + if (!wsi->client_suppress_CONNECTION_ERROR) + wsi->protocol->callback(wsi, + LWS_CALLBACK_CLIENT_CONNECTION_ERROR, + wsi->user_space, arg, len); } #endif diff --git a/lib/core-net/connect.c b/lib/core-net/connect.c index 6d951ae3d..25db2001c 100644 --- a/lib/core-net/connect.c +++ b/lib/core-net/connect.c @@ -58,7 +58,11 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) if (wsi == NULL) goto bail; - + /* + * Until we exit, we can report connection failure directly to the + * caller without needing to call through to protocol CONNECTION_ERROR. + */ + wsi->client_suppress_CONNECTION_ERROR = 1; wsi->context = i->context; wsi->desc.sockfd = LWS_SOCK_INVALID; @@ -349,9 +353,16 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) /* fallthru */ - lws_http_client_connect_via_info2(wsi); + wsi = lws_http_client_connect_via_info2(wsi); } + if (wsi) + /* + * If it subsequently fails, report CONNECTION_ERROR, + * because we're going to return a non-error return now. + */ + wsi->client_suppress_CONNECTION_ERROR = 0; + return wsi; #if defined(LWS_WITH_TLS) diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index 0d1556a55..d79296ec2 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -822,6 +822,9 @@ struct lws { unsigned int client_mux_migrated:1; unsigned int client_subsequent_mime_part:1; unsigned int client_no_follow_redirect:1; + unsigned int client_suppress_CONNECTION_ERROR:1; + /**< because the client connection creation api is still the parent of + * this activity, and will report the failure */ #endif #ifdef _WIN32