Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5e1804eb373e303a701daf25b01d0133c157542b
      
https://github.com/WebKit/WebKit/commit/5e1804eb373e303a701daf25b01d0133c157542b
  Author: Youenn Fablet <[email protected]>
  Date:   2026-07-30 (Thu, 30 Jul 2026)

  Changed paths:
    A LayoutTests/http/wpt/service-workers/upload-stream-backpressure-worker.js
    A 
LayoutTests/http/wpt/service-workers/upload-stream-backpressure.https-expected.txt
    A LayoutTests/http/wpt/service-workers/upload-stream-backpressure.https.html
    M Source/WebCore/Modules/fetch/FetchBody.cpp
    M Source/WebCore/Modules/streams/ReadableStreamToSharedBufferSink.cpp
    M Source/WebCore/Modules/streams/ReadableStreamToSharedBufferSink.h
    M Source/WebCore/platform/network/PendingStreamState.cpp
    M Source/WebCore/platform/network/PendingStreamState.h
    M Source/WebCore/platform/network/cf/FormDataStreamCFNet.mm
    M
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp
    M Source/WebKit/WebProcess/Network/WebResourceLoader.cpp
    M Source/WebKit/WebProcess/Network/WebResourceLoader.h
    M Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in

  Log Message:
  -----------
  Implement fetch upload backpressure
https://bugs.webkit.org/show_bug.cgi?id=320436
rdar://problem/183400867

Reviewed by Alex Christensen.

To implement backpressure, we do the following:
- ReadableStreamToSharedBufferSink is taking an optional max buffered size 
parameter. When reported size is above a threshold, it stops reading the 
readable stream.
- ReadableStreamToSharedBufferSink is registering a drained buffer to the 
PendingStreamState it is sharing with WebResourceLoader. Whenever it sees that 
more data is needed, it restarts reading.
- WebResourceLoader is getting data from ReadableStreamToSharedBufferSink via 
its PendingStreamState. After having sent some data
(256ko), it waits for network process to notify whether it should send more. 
Network process does notify via two mechanisms:
  1. Either service worker is reading the body and upload streaming is 
forwarded to service worker. In that case, backpressure is removed and all data 
goes to the service worker.
  2. Or the upload is going to the network via 
NetworkResourceLoader/FormDataStreamCFNet, in which case the network process is 
sending back to web process the bytes that have been sent.

Covered by newly added test.

* LayoutTests/http/wpt/service-workers/upload-stream-backpressure-worker.js: 
Added.
(event.url.searchParams):
(event.event.respondWith.async await):
(event.event.respondWith):
* 
LayoutTests/http/wpt/service-workers/upload-stream-backpressure.https-expected.txt:
 Added.
* LayoutTests/http/wpt/service-workers/upload-stream-backpressure.https.html: 
Added.
* Source/WebCore/Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::startPendingStreamUpload):
*
Source/WebCore/Modules/streams/ReadableStreamToSharedBufferSink.cpp:
(WebCore::ReadableStreamToSharedBufferSink::ReadableStreamToSharedBufferSink):
(WebCore::ReadableStreamToSharedBufferSink::enqueue):
(WebCore::ReadableStreamToSharedBufferSink::resumeReading):
(WebCore::ReadableStreamToSharedBufferSink::scheduleKeepReading):
* Source/WebCore/Modules/streams/ReadableStreamToSharedBufferSink.h:
* Source/WebCore/platform/network/PendingStreamState.cpp:
(WebCore::PendingStreamState::appendData):
(WebCore::PendingStreamState::endStream):
(WebCore::PendingStreamState::errorStream):
(WebCore::PendingStreamState::setDataAvailableHandler):
(WebCore::PendingStreamState::setQueueDrainedHandler):
(WebCore::PendingStreamState::read):
(WebCore::PendingStreamState::takeNextChunk):
* Source/WebCore/platform/network/PendingStreamState.h:
(WebCore::PendingStreamState::WTF_GUARDED_BY_LOCK):
* Source/WebCore/platform/network/cf/FormDataStreamCFNet.mm:
*
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
(WebKit::WebSWServerToContextConnection::startPendingStreamUploadForwarding):
* Source/WebKit/WebProcess/Network/WebResourceLoader.cpp:
(WebKit::WebResourceLoader::initPendingStreamState):
(WebKit::WebResourceLoader::drainPendingStreamIfPossible):
(WebKit::WebResourceLoader::serviceWorkerPendingStreamForwardingStarted):
(WebKit::WebResourceLoader::didSendData):
* Source/WebKit/WebProcess/Network/WebResourceLoader.h:
* Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in:

Canonical link: 
https://flagged.apple.com:443/proxy?t2=DQ4o7M1Ns6&o=aHR0cHM6Ly9jb21taXRzLndlYmtpdC5vcmcvMzE4MjM2QG1haW4=&emid=7bd1e2ab-7629-4881-9435-05f83493aaf0&c=11



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to