ladybird/Libraries/LibWeb/Fetch/Fetching
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
..
Checks.cpp LibWeb: Store HTTP methods and headers as ByteString 2025-11-26 09:15:06 -05:00
Checks.h Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
FetchedDataReceiver.cpp LibWeb: Fix race in MIME sniff bytes when response completes early 2026-03-08 11:39:41 +01:00
FetchedDataReceiver.h LibWeb: Support MIME type sniffing for streaming HTTP responses 2026-01-24 15:21:26 +01:00
Fetching.cpp LibWeb/Fetch: Prevent file:// URLs from calling fetch() API 2026-02-21 23:00:57 +01:00
Fetching.h LibHTTP+LibWeb: Move the IncludeCredentials enum to LibHTTP 2026-02-10 12:21:20 +01:00
PendingResponse.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
PendingResponse.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
RefCountedFlag.cpp Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
RefCountedFlag.h Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00