Skip to content

Truly independent web browser

LibWeb: Let a fetch engine control the network transports it has

Luke Wilded9b9b9e9776f
diff --git a/Libraries/LibWeb/Fetch/Engine/EngineCommand.h b/Libraries/LibWeb/Fetch/Engine/EngineCommand.h
index 8bafe1660cd..5a64aa19ce4 100644
--- a/Libraries/LibWeb/Fetch/Engine/EngineCommand.h
+++ b/Libraries/LibWeb/Fetch/Engine/EngineCommand.h
@@ -6,10 +6,13 @@
#pragma once
+#include <AK/NonnullRefPtr.h>
#include <AK/Variant.h>
#include <LibIPC/TransportHandle.h>
#include <LibWeb/Fetch/Engine/BodyPresentation.h>
+#include <LibWeb/Fetch/Engine/FetchBodyDeliveryGate.h>
#include <LibWeb/Fetch/Engine/Ids.h>
+#include <LibWeb/Fetch/Engine/NetworkTransportHandle.h>
#include <LibWeb/Fetch/Engine/StartFetchInput.h>
namespace Web::Fetch::Engine::Command {
@@ -60,18 +63,25 @@ struct PreloadResponseResolved {
};
struct TransportControl {
- struct ResumeBodyDeliveryUpTo {
+ struct StopTransport { };
+ struct ReleaseNavigationHold { };
+ struct ReleaseNavigationHoldUpTo {
u64 byte_count { 0 };
};
- struct PauseBodyDelivery { };
- struct StopTransport { };
- using Operation = Variant<ResumeBodyDeliveryUpTo, PauseBodyDelivery, StopTransport>;
+ using Operation = Variant<StopTransport, ReleaseNavigationHold, ReleaseNavigationHoldUpTo>;
RequestId request_id;
TransportEpoch transport_epoch;
Operation operation;
};
+// The transport of a navigation body the agent adopted by its transfer lease, whose controls the engine applies from
+// then on.
+struct NavigationBodyAdopted {
+ NonnullRefPtr<NetworkTransportHandle> handle;
+ NonnullRefPtr<FetchBodyDeliveryGate> delivery_gate;
+};
+
struct AdoptNetworkTransport {
IPC::TransportHandle handle;
};
@@ -88,6 +98,7 @@ using EngineCommand = Variant<
Command::ResolveRedirect,
Command::PreloadResponseResolved,
Command::TransportControl,
+ Command::NavigationBodyAdopted,
Command::AdoptNetworkTransport>;
}
diff --git a/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.cpp b/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.cpp
index 1e34df7b15e..cda30c70ed5 100644
--- a/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.cpp
+++ b/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.cpp
@@ -45,6 +45,12 @@ void FetchEngineRecord::stop_cors_preflight_body_transport()
transport->stop();
}
+void FetchEngineRecord::add_network_transport(NetworkTransportHandle& handle, FetchBodyDeliveryGate& delivery_gate)
+{
+ if (auto* records = m_records.ptr())
+ records->add_network_transport(handle, delivery_gate);
+}
+
void FetchEngineRecords::Agent::misbehaved(StringView reason)
{
dbgln("FetchEngineRecords: The agent misbehaved: {}", reason);
@@ -81,6 +87,52 @@ void FetchEngineRecords::stop_body_transport(FetchId fetch_id)
(*record)->stop_body_transport();
}
+void FetchEngineRecords::add_network_transport(NetworkTransportHandle& handle, FetchBodyDeliveryGate& delivery_gate)
+{
+ ASSERT(is_on_owner_thread());
+ if (m_network_transport_count >= m_network_transport_count_to_sweep_at)
+ forget_network_transports_that_are_gone();
+
+ auto& client_transports = m_network_transports.ensure(handle.transport_epoch());
+ client_transports.highest_request_id = max(client_transports.highest_request_id, handle.request_id());
+ auto result = client_transports.transports.set(handle.request_id(), { handle, delivery_gate });
+ if (result == HashSetResult::InsertedNewEntry)
+ ++m_network_transport_count;
+}
+
+void FetchEngineRecords::forget_network_transports_that_are_gone()
+{
+ m_network_transport_count = 0;
+ for (auto& [transport_epoch, client_transports] : m_network_transports) {
+ client_transports.transports.remove_all_matching([](auto&, auto& transport) { return !transport.handle; });
+ m_network_transport_count += client_transports.transports.size();
+ }
+ m_network_transport_count_to_sweep_at = max(smallest_network_transport_count_to_sweep_at, 2 * m_network_transport_count);
+}
+
+void FetchEngineRecords::control_network_transport(Command::TransportControl const& control)
+{
+ ASSERT(is_on_owner_thread());
+ auto client_transports = m_network_transports.get(control.transport_epoch);
+ if (!client_transports.has_value() || control.request_id > client_transports->highest_request_id) {
+ m_agent->misbehaved("The agent controlled a network transport the engine never had"sv);
+ return;
+ }
+
+ auto transport = client_transports->transports.get(control.request_id);
+ if (!transport.has_value())
+ return;
+ auto handle = transport->handle.strong_ref();
+ if (!handle)
+ return;
+ auto delivery_gate = transport->delivery_gate;
+
+ control.operation.visit(
+ [&](Command::TransportControl::StopTransport) { handle->stop(); },
+ [&](Command::TransportControl::ReleaseNavigationHold) { delivery_gate->release_hold(); },
+ [&](Command::TransportControl::ReleaseNavigationHoldUpTo const& release) { delivery_gate->release_hold_up_to(release.byte_count); });
+}
+
void FetchEngineRecords::remove(Badge<FetchEngineRecord>, FetchId fetch_id)
{
ASSERT(is_on_owner_thread());
diff --git a/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.h b/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.h
index a618f630e6c..08fbf6be630 100644
--- a/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.h
+++ b/Libraries/LibWeb/Fetch/Engine/FetchEngineRecord.h
@@ -19,11 +19,13 @@
#include <AK/Weakable.h>
#include <AK/kmalloc.h>
#include <LibWeb/Export.h>
+#include <LibWeb/Fetch/Engine/EngineCommand.h>
#include <LibWeb/Fetch/Engine/EngineEventSink.h>
#include <LibWeb/Fetch/Engine/FetchBodyDeliveryGate.h>
#include <LibWeb/Fetch/Engine/Ids.h>
#include <LibWeb/Fetch/Engine/NetworkActivity.h>
#include <LibWeb/Fetch/Engine/NetworkActivityObservers.h>
+#include <LibWeb/Fetch/Engine/NetworkTransportHandle.h>
namespace Web::Fetch::Engine {
@@ -55,6 +57,8 @@ public:
void set_cors_preflight_body_transport(FetchBodyDeliveryGate::Transport&);
void stop_cors_preflight_body_transport();
+ void add_network_transport(NetworkTransportHandle&, FetchBodyDeliveryGate&);
+
private:
friend class FetchEngineRecords;
@@ -68,8 +72,9 @@ private:
WeakPtr<FetchBodyDeliveryGate::Transport> m_cors_preflight_body_transport;
};
-// The records of the fetches an engine has started, by fetch id. A record stays only while something else holds it.
-// Every method, and each record's destruction, runs on the loop the records were created on.
+// The records of the fetches an engine has started, by fetch id, and the network transports it controls. A record stays
+// only while something else holds it. Every method, and each record's destruction, runs on the loop the records were
+// created on.
class WEB_API FetchEngineRecords : public Weakable<FetchEngineRecords> {
AK_MAKE_NONCOPYABLE(FetchEngineRecords);
AK_MAKE_NONMOVABLE(FetchEngineRecords);
@@ -94,15 +99,41 @@ public:
// Does nothing once the fetch's record is gone. Reports to the agent a fetch id above that of every started fetch.
void stop_body_transport(FetchId);
+ // Records a network transport, which the agent's transport controls name by the id and transport epoch of its
+ // request.
+ void add_network_transport(NetworkTransportHandle&, FetchBodyDeliveryGate&);
+ // Does nothing once the transport is gone. Reports to the agent a client the engine had no transport of, or a request
+ // id above every one it had for that client.
+ void control_network_transport(Command::TransportControl const&);
+
void remove(Badge<FetchEngineRecord>, FetchId);
+ // Adding a network transport forgets those that are gone once the records hold twice as many as the last sweep left,
+ // and at least this many.
+ static constexpr size_t smallest_network_transport_count_to_sweep_at = 32;
+
private:
[[nodiscard]] bool is_on_owner_thread() const { return m_owner_thread.is_current_thread(); }
+ void forget_network_transports_that_are_gone();
+
NonnullOwnPtr<Agent> m_agent;
AK::ThreadID m_owner_thread { AK::ThreadID::current() };
FetchId m_last_started_fetch_id { 0 };
HashMap<FetchId, FetchEngineRecord*> m_records;
+
+ struct NetworkTransport {
+ WeakPtr<NetworkTransportHandle> handle;
+ NonnullRefPtr<FetchBodyDeliveryGate> delivery_gate;
+ };
+ // The network transports of the requests of one RequestServer client.
+ struct ClientNetworkTransports {
+ RequestId highest_request_id { 0 };
+ HashMap<RequestId, NetworkTransport> transports;
+ };
+ HashMap<TransportEpoch, ClientNetworkTransports> m_network_transports;
+ size_t m_network_transport_count { 0 };
+ size_t m_network_transport_count_to_sweep_at { smallest_network_transport_count_to_sweep_at };
};
}
diff --git a/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.cpp b/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.cpp
index 695848f4b72..c69f34db743 100644
--- a/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.cpp
+++ b/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.cpp
@@ -18,43 +18,56 @@ NetworkTransportHandle::NetworkTransportHandle(NonnullRefPtr<Requests::Request>
{
}
+NetworkTransportHandle::~NetworkTransportHandle()
+{
+ ASSERT(is_on_owner_thread());
+}
+
bool NetworkTransportHandle::has_file_backed_response_body() const
{
+ ASSERT(is_on_owner_thread());
return m_request->has_file_backed_response_body();
}
void NetworkTransportHandle::resume_body_delivery_up_to(u64 byte_count)
{
+ ASSERT(is_on_owner_thread());
m_request->resume_body_delivery_up_to(byte_count);
}
void NetworkTransportHandle::pause_body_delivery()
{
+ ASSERT(is_on_owner_thread());
m_request->set_body_delivery_paused(true);
}
void NetworkTransportHandle::stop()
{
+ ASSERT(is_on_owner_thread());
m_request->stop();
}
void NetworkTransportHandle::release_transfer_lease()
{
+ ASSERT(is_on_owner_thread());
m_request->release_transfer_lease();
}
void NetworkTransportHandle::set_on_requires_network(Function<void()> on_requires_network)
{
+ ASSERT(is_on_owner_thread());
m_request->on_requires_network = move(on_requires_network);
}
void NetworkTransportHandle::set_on_upload_progress(Function<void(u64 bytes_sent)> on_upload_progress)
{
+ ASSERT(is_on_owner_thread());
m_request->on_upload_progress = move(on_upload_progress);
}
void NetworkTransportHandle::set_on_teardown(Function<void(Requests::Request::TeardownReason)> on_teardown)
{
+ ASSERT(is_on_owner_thread());
m_request->on_teardown = move(on_teardown);
}
diff --git a/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.h b/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.h
index 10c26854a6c..1b6c040f0da 100644
--- a/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.h
+++ b/Libraries/LibWeb/Fetch/Engine/NetworkTransportHandle.h
@@ -7,6 +7,7 @@
#pragma once
#include <AK/Function.h>
+#include <AK/ThreadID.h>
#include <LibRequests/Request.h>
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Engine/FetchBodyDeliveryGate.h>
@@ -14,13 +15,15 @@
namespace Web::Fetch::Engine {
-// Controls the RequestServer request a fetch's response arrives through. Every method runs on the loop the handle
-// was created on.
+// Controls the RequestServer request a fetch's response arrives through. Every method, and the handle's destruction,
+// runs on the loop the handle was created on.
class WEB_API NetworkTransportHandle final : public FetchBodyDeliveryGate::Transport {
public:
[[nodiscard]] static NonnullRefPtr<NetworkTransportHandle> create(NonnullRefPtr<Requests::Request>);
+ virtual ~NetworkTransportHandle() override;
[[nodiscard]] RequestId request_id() const { return RequestId { m_request->id() }; }
+ [[nodiscard]] TransportEpoch transport_epoch() const { return TransportEpoch { m_request->transport_epoch() }; }
// The key another client adopts the request by, while this process holds its lease.
[[nodiscard]] Optional<Requests::RequestTransferLeaseKey> const& transfer_lease() const { return m_request->transfer_lease(); }
@@ -41,7 +44,10 @@ public:
private:
explicit NetworkTransportHandle(NonnullRefPtr<Requests::Request>);
+ [[nodiscard]] bool is_on_owner_thread() const { return m_owner_thread.is_current_thread(); }
+
NonnullRefPtr<Requests::Request> m_request;
+ AK::ThreadID m_owner_thread { AK::ThreadID::current() };
};
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/FetchEngine.cpp b/Libraries/LibWeb/Fetch/Fetching/FetchEngine.cpp
index 6e7d0145097..4340a7865b6 100644
--- a/Libraries/LibWeb/Fetch/Fetching/FetchEngine.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/FetchEngine.cpp
@@ -32,7 +32,8 @@ void FetchEngine::handle_command(Engine::EngineCommand command)
[this](Engine::Command::Stop const& stop) { m_records.stop_body_transport(stop.fetch_id); },
[](Engine::Command::ResolveRedirect const&) { VERIFY_NOT_REACHED(); },
[](Engine::Command::PreloadResponseResolved const&) { VERIFY_NOT_REACHED(); },
- [](Engine::Command::TransportControl const&) { VERIFY_NOT_REACHED(); },
+ [this](Engine::Command::TransportControl const& control) { m_records.control_network_transport(control); },
+ [this](Engine::Command::NavigationBodyAdopted const& adopted) { m_records.add_network_transport(*adopted.handle, *adopted.delivery_gate); },
[](Engine::Command::AdoptNetworkTransport const&) { VERIFY_NOT_REACHED(); });
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index 4e1a1328db3..c812491cd5d 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -2752,6 +2752,10 @@ GC::Ptr<Infrastructure::Body> adopt_navigation_response_body(JS::Realm& realm, I
auto network_transport = Engine::NetworkTransportHandle::create(*request);
body_pump->delivery_gate()->attach_transport(network_transport);
+ auto& fetch_executor = *HTML::relevant_agent(realm.global_object()).fetch_executor;
+ Engine::Command::NavigationBodyAdopted adopted { network_transport, body_pump->delivery_gate() };
+ fetch_executor.post(move(adopted));
+
// The observer hears the body's end at most once.
auto network_settled = GC::make_root(on_network_settled);
network_transport->set_on_teardown([body_pump, network_settled](Requests::Request::TeardownReason reason) {
@@ -3057,6 +3061,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
if (network_transport) {
engine_record->report_network_activity(network_transport->request_id(), network_request_started(load_request, *request));
body_pump->delivery_gate()->attach_transport(*network_transport);
+ engine_record->add_network_transport(*network_transport, *body_pump->delivery_gate());
network_transport->set_on_teardown([body_pump = GC::Root { body_pump }](Requests::Request::TeardownReason reason) {
body_pump->handle_network_teardown(reason);
});
diff --git a/Tests/LibWeb/TestFetchEngineMessages.cpp b/Tests/LibWeb/TestFetchEngineMessages.cpp
index 757e54a1203..2e463d01a4b 100644
--- a/Tests/LibWeb/TestFetchEngineMessages.cpp
+++ b/Tests/LibWeb/TestFetchEngineMessages.cpp
@@ -35,7 +35,7 @@ TEST_CASE(commands_round_trip_their_payloads)
.fetch_id = FetchId(7),
.response = { .outcome = Command::CompletedPreloadResponse::Completed { .body = Delivered<Core::ImmutableBytes> { Core::ImmutableBytes::adopt(MUST(ByteBuffer::copy("preloaded"sv.bytes()))) } } },
});
- commands.append(Command::TransportControl { .request_id = RequestId(8), .transport_epoch = TransportEpoch(9), .operation = Command::TransportControl::ResumeBodyDeliveryUpTo { .byte_count = 4096 } });
+ commands.append(Command::TransportControl { .request_id = RequestId(8), .transport_epoch = TransportEpoch(9), .operation = Command::TransportControl::ReleaseNavigationHoldUpTo { .byte_count = 4096 } });
Vector<u64> seen_ids;
for (auto& command : commands) {
@@ -56,9 +56,10 @@ TEST_CASE(commands_round_trip_their_payloads)
},
[&](Command::TransportControl const& control) {
EXPECT_EQ(control.transport_epoch, TransportEpoch(9));
- EXPECT_EQ(control.operation.get<Command::TransportControl::ResumeBodyDeliveryUpTo>().byte_count, 4096u);
+ EXPECT_EQ(control.operation.get<Command::TransportControl::ReleaseNavigationHoldUpTo>().byte_count, 4096u);
seen_ids.append(control.request_id.value());
},
+ [&](Command::NavigationBodyAdopted const&) { FAIL("no navigation body was adopted"); },
[&](Command::AdoptNetworkTransport const&) { FAIL("no transport was posted"); });
}
EXPECT_EQ(seen_ids, (Vector<u64> { 2, 3, 4, 5, 7, 8 }));
diff --git a/Tests/LibWeb/TestFetchEngineRecord.cpp b/Tests/LibWeb/TestFetchEngineRecord.cpp
index 3c17e8242c0..74bafcb56af 100644
--- a/Tests/LibWeb/TestFetchEngineRecord.cpp
+++ b/Tests/LibWeb/TestFetchEngineRecord.cpp
@@ -4,8 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibCore/EventLoop.h>
+#include <LibIPC/Transport.h>
+#include <LibRequests/RequestClient.h>
#include <LibTest/TestCase.h>
+#include <LibURL/Parser.h>
#include <LibWeb/Fetch/Engine/FetchEngineRecord.h>
+#include <LibWeb/Fetch/Engine/NetworkTransportHandle.h>
#include <LibWeb/Fetch/Engine/WholeBodyTransport.h>
using namespace Web::Fetch::Engine;
@@ -17,6 +22,23 @@ public:
virtual void handle_event(EngineEvent) override { }
};
+// A RequestServer client whose RequestServer end of the connection is held, and never read.
+struct ConnectedClient {
+ NonnullRefPtr<Requests::RequestClient> client;
+ IPC::TransportHandle request_server;
+};
+
+struct TeardownReasons : RefCounted<TeardownReasons> {
+ Vector<Requests::Request::TeardownReason> reasons;
+};
+
+// The transport of a request, and a delivery gate that holds a body for its navigation, with no transport attached.
+struct NetworkTransportWithGate {
+ NonnullRefPtr<NetworkTransportHandle> handle;
+ NonnullRefPtr<TeardownReasons> teardowns;
+ NonnullRefPtr<FetchBodyDeliveryGate> delivery_gate;
+};
+
}
static NonnullRefPtr<FetchEngineRecord> start_fetch(FetchEngineRecords& records, u64 fetch_id)
@@ -64,6 +86,107 @@ TEST_CASE(a_stop_of_a_fetch_whose_record_is_gone_stops_nothing)
EXPECT(!stopped);
}
+static ConnectedClient connect_client()
+{
+ auto pair = MUST(IPC::Transport::create_paired());
+ auto client = make_ref_counted<Requests::RequestClient>(move(pair.local), 1);
+ return { move(client), move(pair.remote_handle) };
+}
+
+static NetworkTransportWithGate start_network_transport(Requests::RequestClient& client)
+{
+ auto url = URL::Parser::basic_parse("https://example.com/"sv);
+ VERIFY(url.has_value());
+ auto request = client.start_request("GET"sv, *url, HTTP::Cookie::SameSiteContext {});
+ VERIFY(request);
+
+ auto handle = NetworkTransportHandle::create(request.release_nonnull());
+ auto teardowns = make_ref_counted<TeardownReasons>();
+ handle->set_on_teardown([teardowns](Requests::Request::TeardownReason reason) { teardowns->reasons.append(reason); });
+ auto delivery_gate = FetchBodyDeliveryGate::create(FetchBodyDeliveryGate::NavigationHold::Held);
+ delivery_gate->grant_credit(100);
+ return { move(handle), move(teardowns), move(delivery_gate) };
+}
+
+static Command::TransportControl control_of(NetworkTransportHandle const& handle, Command::TransportControl::Operation operation)
+{
+ return { .request_id = handle.request_id(), .transport_epoch = handle.transport_epoch(), .operation = move(operation) };
+}
+
+TEST_CASE(a_transport_control_reaches_only_the_transport_with_its_request_id_and_epoch)
+{
+ Core::EventLoop event_loop;
+ FetchEngineRecords records { make<FetchEngineRecords::Agent>() };
+
+ // Request ids start again for each client, as for a client that replaces one whose RequestServer died.
+ auto first_client = connect_client();
+ auto second_client = connect_client();
+ auto first = start_network_transport(*first_client.client);
+ auto second = start_network_transport(*second_client.client);
+ EXPECT_EQ(first.handle->request_id(), second.handle->request_id());
+ records.add_network_transport(*first.handle, *first.delivery_gate);
+ records.add_network_transport(*second.handle, *second.delivery_gate);
+
+ records.control_network_transport(control_of(*second.handle, Command::TransportControl::ReleaseNavigationHoldUpTo { .byte_count = 10 }));
+ EXPECT(second.delivery_gate->did_deliver(10) == FetchBodyDeliveryGate::DeliveryResult::Accepted);
+ EXPECT(second.delivery_gate->did_deliver(1) == FetchBodyDeliveryGate::DeliveryResult::Rejected);
+ EXPECT(first.delivery_gate->did_deliver(1) == FetchBodyDeliveryGate::DeliveryResult::Rejected);
+
+ records.control_network_transport(control_of(*first.handle, Command::TransportControl::ReleaseNavigationHold {}));
+ EXPECT(first.delivery_gate->did_deliver(100) == FetchBodyDeliveryGate::DeliveryResult::Accepted);
+
+ records.control_network_transport(control_of(*first.handle, Command::TransportControl::StopTransport {}));
+ EXPECT(first.teardowns->reasons == (Vector<Requests::Request::TeardownReason> { Requests::Request::TeardownReason::Stopped }));
+ EXPECT(second.teardowns->reasons.is_empty());
+}
+
+TEST_CASE(a_transport_control_of_a_network_transport_that_is_gone_does_nothing)
+{
+ Core::EventLoop event_loop;
+ FetchEngineRecords records { make<FetchEngineRecords::Agent>() };
+
+ auto connected = connect_client();
+ auto delivery_gate = FetchBodyDeliveryGate::create(FetchBodyDeliveryGate::NavigationHold::Held);
+ delivery_gate->grant_credit(100);
+ Optional<Command::TransportControl> release_hold;
+ {
+ auto transport = start_network_transport(*connected.client);
+ records.add_network_transport(*transport.handle, *delivery_gate);
+ release_hold = control_of(*transport.handle, Command::TransportControl::ReleaseNavigationHold {});
+ }
+
+ // Adding enough of another client's transports forgets the one that is gone.
+ auto other_client = connect_client();
+ Vector<NetworkTransportWithGate> others;
+ for (size_t i = 0; i < FetchEngineRecords::smallest_network_transport_count_to_sweep_at; ++i) {
+ auto other = start_network_transport(*other_client.client);
+ records.add_network_transport(*other.handle, *other.delivery_gate);
+ others.append(move(other));
+ }
+
+ records.control_network_transport(*release_hold);
+ EXPECT(delivery_gate->did_deliver(1) == FetchBodyDeliveryGate::DeliveryResult::Rejected);
+}
+
+TEST_CASE(a_transport_control_of_a_request_the_engine_never_had_dies)
+{
+ Core::EventLoop event_loop;
+ FetchEngineRecords records { make<FetchEngineRecords::Agent>() };
+
+ auto connected = connect_client();
+ auto transport = start_network_transport(*connected.client);
+ records.add_network_transport(*transport.handle, *transport.delivery_gate);
+
+ auto above = control_of(*transport.handle, Command::TransportControl::StopTransport {});
+ above.request_id = RequestId { above.request_id.value() + 1 };
+ EXPECT_DEATH("Controlling a request with an id above those of its client's requests the engine had", records.control_network_transport(above));
+
+ auto other_client = connect_client();
+ auto of_other_client = control_of(*transport.handle, Command::TransportControl::StopTransport {});
+ of_other_client.transport_epoch = TransportEpoch { other_client.client->transport_epoch() };
+ EXPECT_DEATH("Controlling a request of a client the engine had none of", records.control_network_transport(of_other_client));
+}
+
TEST_CASE(a_start_of_a_fetch_out_of_fetch_id_order_dies)
{
FetchEngineRecords records { make<FetchEngineRecords::Agent>() };