From b77643a2e829fa9971a7718449ec63bf6b07a0f1 Mon Sep 17 00:00:00 2001 From: Mohamed amine Bounya Date: Fri, 14 Mar 2025 01:13:04 +0000 Subject: [PATCH] RequestServer: Don't assert for socket fd not being CURL_SOCKET_BAD The assertion in `WebSocketImplCurl::did_connect()` keeps failing for multiple websockets when loading `https://www.speedtest.net/` since commit 14ebcd4. This fixes that by checking and returning false if something went wrong and letting the caller function handle it. --- Services/RequestServer/ConnectionFromClient.cpp | 8 +++++--- Services/RequestServer/WebSocketImplCurl.cpp | 6 ++++-- Services/RequestServer/WebSocketImplCurl.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Services/RequestServer/ConnectionFromClient.cpp b/Services/RequestServer/ConnectionFromClient.cpp index 393e50a2889..6c90f3def1c 100644 --- a/Services/RequestServer/ConnectionFromClient.cpp +++ b/Services/RequestServer/ConnectionFromClient.cpp @@ -625,10 +625,12 @@ void ConnectionFromClient::check_active_requests() // FIXME: Come up with a unified way to track websockets and standard fetches instead of this nasty tagged pointer if (reinterpret_cast(application_private) & websocket_private_tag) { auto* websocket_impl = reinterpret_cast(reinterpret_cast(application_private) & ~websocket_private_tag); - if (msg->data.result == CURLE_OK) - websocket_impl->did_connect(); - else + if (msg->data.result == CURLE_OK) { + if (!websocket_impl->did_connect()) + websocket_impl->on_connection_error(); + } else { websocket_impl->on_connection_error(); + } continue; } diff --git a/Services/RequestServer/WebSocketImplCurl.cpp b/Services/RequestServer/WebSocketImplCurl.cpp index fa496738f48..b541374c1a2 100644 --- a/Services/RequestServer/WebSocketImplCurl.cpp +++ b/Services/RequestServer/WebSocketImplCurl.cpp @@ -160,11 +160,12 @@ void WebSocketImplCurl::discard_connection() } } -void WebSocketImplCurl::did_connect() +bool WebSocketImplCurl::did_connect() { curl_socket_t socket_fd = CURL_SOCKET_BAD; auto res = curl_easy_getinfo(m_easy_handle, CURLINFO_ACTIVESOCKET, &socket_fd); - VERIFY(res == CURLE_OK && socket_fd != CURL_SOCKET_BAD); + if (res != CURLE_OK || socket_fd == CURL_SOCKET_BAD) + return false; m_read_notifier = Core::Notifier::construct(socket_fd, Core::Notifier::Type::Read); m_read_notifier->on_activation = [this] { @@ -190,6 +191,7 @@ void WebSocketImplCurl::did_connect() }; on_connected(); + return true; } } diff --git a/Services/RequestServer/WebSocketImplCurl.h b/Services/RequestServer/WebSocketImplCurl.h index 1ee959781a9..25f0500e5bc 100644 --- a/Services/RequestServer/WebSocketImplCurl.h +++ b/Services/RequestServer/WebSocketImplCurl.h @@ -29,7 +29,7 @@ public: virtual bool handshake_complete_when_connected() const override { return true; } - void did_connect(); + bool did_connect(); private: explicit WebSocketImplCurl(CURLM*);