ladybird/Libraries/LibWeb/Fetch
Andreas Kling 7b2bb4d49c LibWeb: Fix race in MIME sniff bytes when response completes early
When a streaming HTTP response completes before set_body() is called
on the FetchedDataReceiver, the sniff bytes would never be marked as
complete, causing navigation to hang intermittently.

The sequence that triggers this:

1. handle_network_bytes(data, Ongoing) runs, but m_body is null,
   so bytes only go into the FetchedDataReceiver's own m_buffer.
2. handle_network_bytes({}, Complete) runs, but m_body is still
   null, so the m_body->set_sniff_bytes_complete() call is skipped.
3. set_body(body) is called, which flushes m_buffer into the body
   via append_sniff_bytes(), but never marks them as complete.
4. populate_session_history_entry_document() calls
   sniff_bytes_if_available() on the body. Since the source is
   Empty (streaming) and m_sniff_bytes_complete is false, it
   returns no value.
5. The async path registers a callback via wait_for_sniff_bytes(),
   but since the stream already completed, no more data arrives,
   and the callback never fires. Navigation hangs.

Fix this by checking the lifecycle state in set_body(). If we have
already moved past the Receiving state, the Complete was already
processed and we need to mark sniff bytes as complete now.
2026-03-08 11:39:41 +01:00
..
Fetching LibWeb: Fix race in MIME sniff bytes when response completes early 2026-03-08 11:39:41 +01:00
Infrastructure LibWeb: Make more use of Value::{as,as_if,is} in LibWeb 2026-02-28 10:24:37 -05:00
Body.cpp LibWeb: Add missing GC visits for XHR::FormDataEntry 2025-12-26 19:48:46 +01:00
Body.h LibWeb: Add missing GC visits for XHR::FormDataEntry 2025-12-26 19:48:46 +01:00
Body.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
BodyInit.cpp LibWeb: Store HTTP methods and headers as ByteString 2025-11-26 09:15:06 -05:00
BodyInit.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
BodyInit.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Enums.cpp LibHTTP+LibWeb: Move Infrastructure::Request::CacheMode to LibHTTP 2026-01-22 07:05:06 -05:00
Enums.h LibHTTP+LibWeb: Move Infrastructure::Request::CacheMode to LibHTTP 2026-01-22 07:05:06 -05:00
FetchMethod.cpp LibWeb: Remove exception throwing from Fetch 2025-11-07 04:08:30 +01:00
FetchMethod.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
Headers.cpp LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
Headers.h LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
Headers.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
HeadersIterator.cpp LibTextCodec+LibWeb: Move isomorphic coders to LibTextCodec 2025-11-27 14:57:29 +01:00
HeadersIterator.h LibWeb: Give IDL exposed PlatformObjects an InterfaceName 2026-02-14 20:22:40 +01:00
Request.cpp LibHTTP+LibWeb: Move Infrastructure::Request::CacheMode to LibHTTP 2026-01-22 07:05:06 -05:00
Request.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
Request.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Response.cpp LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
Response.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
Response.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00