diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-01-28 21:11:54 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-28 23:29:32 +0100 |
commit | c1184c1fde517993e3f719c7e5aa636197cb2dfc (patch) | |
tree | 1a53214c330a1961fb2d4f8e337d0accb14b9be6 | |
parent | b387ac56b6fbac59db3bc127dfbbeaf4f596a852 (diff) | |
download | serenity-c1184c1fde517993e3f719c7e5aa636197cb2dfc.zip |
RequestServer: Replace disconnected sockets in the grace period too
We previously only replaced disconnected sockets on the queued-request
path, leading to attempts to send requests on a disconnected socket if
the disconnection happened in the deletion grace period.
-rw-r--r-- | Userland/Services/RequestServer/ConnectionCache.cpp | 12 | ||||
-rw-r--r-- | Userland/Services/RequestServer/ConnectionCache.h | 17 |
2 files changed, 18 insertions, 11 deletions
diff --git a/Userland/Services/RequestServer/ConnectionCache.cpp b/Userland/Services/RequestServer/ConnectionCache.cpp index 85ae1c66a2..896e9d2f0d 100644 --- a/Userland/Services/RequestServer/ConnectionCache.cpp +++ b/Userland/Services/RequestServer/ConnectionCache.cpp @@ -50,17 +50,7 @@ void request_did_finish(URL const& url, Core::Socket const* socket) }; connection->removal_timer->start(); } else { - using SocketType = RemoveCVReference<decltype(*connection->socket)>; - bool is_connected; - if constexpr (IsSame<SocketType, TLS::TLSv12>) - is_connected = connection->socket->is_established(); - else - is_connected = connection->socket->is_connected(); - if (!is_connected) { - // Create another socket for the connection. - connection->socket = SocketType::construct(nullptr); - dbgln_if(REQUESTSERVER_DEBUG, "Creating a new socket for {} -> {}", url, connection->socket); - } + recreate_socket_if_needed(*connection, url); dbgln_if(REQUESTSERVER_DEBUG, "Running next job in queue for connection {} @{}", &connection, connection->socket); auto request = connection->request_queue.take_first(); connection->timer.start(); diff --git a/Userland/Services/RequestServer/ConnectionCache.h b/Userland/Services/RequestServer/ConnectionCache.h index 1f9d87c70e..5a91714ffb 100644 --- a/Userland/Services/RequestServer/ConnectionCache.h +++ b/Userland/Services/RequestServer/ConnectionCache.h @@ -68,6 +68,22 @@ void dump_jobs(); constexpr static inline size_t MaxConcurrentConnectionsPerURL = 2; constexpr static inline size_t ConnectionKeepAliveTimeMilliseconds = 10'000; +template<typename T> +void recreate_socket_if_needed(T& connection, URL const& url) +{ + using SocketType = RemoveCVReference<decltype(*connection.socket)>; + bool is_connected; + if constexpr (IsSame<SocketType, TLS::TLSv12>) + is_connected = connection.socket->is_established(); + else + is_connected = connection.socket->is_connected(); + if (!is_connected) { + // Create another socket for the connection. + connection.socket = SocketType::construct(nullptr); + dbgln_if(REQUESTSERVER_DEBUG, "Creating a new socket for {} -> {}", url, connection.socket); + } +} + decltype(auto) get_or_create_connection(auto& cache, URL const& url, auto& job) { using CacheEntryType = RemoveCVReference<decltype(*cache.begin()->value)>; @@ -105,6 +121,7 @@ decltype(auto) get_or_create_connection(auto& cache, URL const& url, auto& job) } auto& connection = sockets_for_url[index]; if (!connection.has_started) { + recreate_socket_if_needed(connection, url); dbgln_if(REQUESTSERVER_DEBUG, "Immediately start request for url {} in {} - {}", url, &connection, connection.socket); connection.has_started = true; connection.removal_timer->stop(); |