RESOLVED FIXED256698
ServiceWorker downloads fail when chunks are sent via postMessage
https://bugs.webkit.org/show_bug.cgi?id=256698
Summary ServiceWorker downloads fail when chunks are sent via postMessage
mrskman
Reported 2023-05-12 05:06:02 PDT
Steps to reproduce: 1) Go to https://stat-info.cz/safari-sw-download-tests.html 2) Start download using Test #3 (4 GiB at least) It looks like the ServiceWorker thread is killed usually after downloading 1-2 GiB. This doesn't happen when chunks are downloaded inside the ServiceWorker thread (tests #1 and #2). Reproduced on iOS 16.4.1 (iPhone XS). Working fine on macOS 13.3.1 in Safari 16.4.
Attachments
Alexey Proskuryakov
Comment 1 2023-05-12 08:55:48 PDT
This sounds like the ServiceWorker process running out of memory. I didn't analyze the test, but is it holding to the downloaded data permanently in RAM? If not, going be a garbage collection problem.
mrskman
Comment 2 2023-05-13 09:40:32 PDT
No, ServiceWorker isn't holding the downloaded data permanently. It holds one chunk at a time in Test #3. The Test #3 works like this: 1) Web page downloads a chunk as a Blob. 2) Blob is passed to the ServiceWorker via postMessage. 3) ServiceWorker converts it to ArrayBuffer. 4) ServiceWorker waits until ReadableStream requests a new chunk via pull method. 5) ServiceWorker passes the ArrayBuffer to ReadableStream. 6) ServiceWorker sends message back to the page via MessageChannel. 7) Page receives the message and goes to step 1) until the download is completed.
Radar WebKit Bug Importer
Comment 3 2023-05-19 05:06:20 PDT
youenn fablet
Comment 4 2023-05-22 01:45:11 PDT
I tried to reproduce now but I do not think I reproduced precisely the issue. I did not see increase of memory usage. Another possibility is that the service worker process is getting suspended, but not the web page somehow. I'll continue trying to reproduce a bit. @mrksman, if you can reproduce easily, can you send me a sysdiagnose (youenn@apple.com) with the timestamp of the bug?
youenn fablet
Comment 5 2023-05-22 04:33:03 PDT
@mrskman sent me a sysdiagnose. The networking process gets jetsamed, which triggers stopping the service workers and failing the download: 2023-05-22 11:34:42.517896+0200 0x327 Default 0x0 0 kernel: (kernel) memorystatus: killing process 5169 [com.apple.WebKit.Networking] in high band FOREGROUND (100) - memorystatus_available_pages: 36200
youenn fablet
Comment 6 2023-05-22 08:25:42 PDT
It seems we have a memory leak with URLKeepingBlobAlive isolatedCopy().
youenn fablet
Comment 7 2023-05-22 09:58:41 PDT
EWS
Comment 8 2023-05-23 02:29:45 PDT
Committed 264412@main (fb9630a9c9fc): <https://commits.webkit.org/264412@main> Reviewed commits have been landed. Closing PR #14184 and removing active labels.
mrskman
Comment 9 2023-05-23 02:34:48 PDT
Thank you for patching this issue! How long does it usually take to get a patch to iOS?
Note You need to log in before you can comment on or make changes to this bug.