From 4c48fb493363aeb8019b90f37a2f24b81582d2ac Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 30 Jan 2023 09:35:39 +0100 Subject: [PATCH] ws: unstick connect-only shutdown As this mode uses blocking sockets, it must set them back to non-blocking in disconnect to avoid the risk of getting stuck. Closes #10366 --- lib/http.c | 4 ++-- lib/urldata.h | 4 ++-- lib/ws.c | 11 +++++++++++ lib/ws.h | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/http.c b/lib/http.c index a33251e5d3..3c1711ab37 100644 --- a/lib/http.c +++ b/lib/http.c @@ -151,7 +151,7 @@ const struct Curl_handler Curl_handler_ws = { http_getsock_do, /* doing_getsock */ ZERO_NULL, /* domore_getsock */ ZERO_NULL, /* perform_getsock */ - ZERO_NULL, /* disconnect */ + Curl_ws_disconnect, /* disconnect */ ZERO_NULL, /* readwrite */ ZERO_NULL, /* connection_check */ ZERO_NULL, /* attach connection */ @@ -205,7 +205,7 @@ const struct Curl_handler Curl_handler_wss = { http_getsock_do, /* doing_getsock */ ZERO_NULL, /* domore_getsock */ ZERO_NULL, /* perform_getsock */ - ZERO_NULL, /* disconnect */ + Curl_ws_disconnect, /* disconnect */ ZERO_NULL, /* readwrite */ ZERO_NULL, /* connection_check */ ZERO_NULL, /* attach connection */ diff --git a/lib/urldata.h b/lib/urldata.h index 2dfe196699..7610b237ae 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -765,8 +765,8 @@ struct Curl_handler { /* This function *MAY* be set to a protocol-dependent function that is run * by the curl_disconnect(), as a step in the disconnection. If the handler * is called because the connection has been considered dead, - * dead_connection is set to TRUE. The connection is already disassociated - * from the transfer here. + * dead_connection is set to TRUE. The connection is (again) associated with + * the transfer here. */ CURLcode (*disconnect)(struct Curl_easy *, struct connectdata *, bool dead_connection); diff --git a/lib/ws.c b/lib/ws.c index 30b5f19ac2..18d7193862 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -710,6 +710,17 @@ void Curl_ws_done(struct Curl_easy *data) Curl_dyn_free(&wsp->buf); } +CURLcode Curl_ws_disconnect(struct Curl_easy *data, + struct connectdata *conn, + bool dead_connection) +{ + (void)data; + (void)dead_connection; + /* make sure this is non-blocking to avoid getting stuck in shutdown */ + (void)curlx_nonblock(conn->sock[FIRSTSOCKET], TRUE); + return CURLE_OK; +} + CURL_EXTERN struct curl_ws_frame *curl_ws_meta(struct Curl_easy *data) { /* we only return something for websocket, called from within the callback diff --git a/lib/ws.h b/lib/ws.h index f07ddb6056..9775a04b94 100644 --- a/lib/ws.h +++ b/lib/ws.h @@ -60,6 +60,9 @@ CURLcode Curl_ws_accept(struct Curl_easy *data); size_t Curl_ws_writecb(char *buffer, size_t size, size_t nitems, void *userp); void Curl_ws_done(struct Curl_easy *data); +CURLcode Curl_ws_disconnect(struct Curl_easy *data, + struct connectdata *conn, + bool dead_connection); #else #define Curl_ws_request(x,y) CURLE_OK -- 2.47.2