RequestServer: Avoid race condition between timeout and socket creation

Part of this issue was fixed in 89877b3f40
but that only addressed the first layer of deferred_invoke, ignoring the
second one (which would cause a race if a request was sent to a host
immediately following a timeout event from the same host).
Fixes #23840.
This commit is contained in:
Ali Mohammad Pur 2024-04-04 23:19:22 +02:00 committed by Andreas Kling
parent 973cc67e81
commit 5485e2a940
Notes: sideshowbarker 2024-07-16 21:34:08 +09:00

View File

@ -56,6 +56,9 @@ void request_did_finish(URL::URL const& url, Core::Socket const* socket)
connection->job_data = {};
connection->removal_timer->on_timeout = [ptr = connection.ptr(), &cache_entry, key = move(key), &cache]() mutable {
Core::deferred_invoke([&, key = move(key), ptr] {
if (ptr->has_started)
return;
dbgln_if(REQUESTSERVER_DEBUG, "Removing no-longer-used connection {} (socket {})", ptr, ptr->socket);
auto did_remove = cache_entry.remove_first_matching([&](auto& entry) { return entry == ptr; });
VERIFY(did_remove);