Bug 256698
| Summary: | ServiceWorker downloads fail when chunks are sent via postMessage | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | mrskman |
| Component: | Service Workers | Assignee: | youenn fablet <youennf> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | ap, cdumez, mark.lam, webkit-bug-importer, youennf |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 16 | ||
| Hardware: | iPhone / iPad | ||
| OS: | iOS 16 | ||
mrskman
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Alexey Proskuryakov
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
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
<rdar://problem/109561888>
youenn fablet
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
@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
It seems we have a memory leak with URLKeepingBlobAlive isolatedCopy().
youenn fablet
Pull request: https://github.com/WebKit/WebKit/pull/14184
EWS
Committed 264412@main (fb9630a9c9fc): <https://commits.webkit.org/264412@main>
Reviewed commits have been landed. Closing PR #14184 and removing active labels.
mrskman
Thank you for patching this issue! How long does it usually take to get a patch to iOS?