Bug 220220

Summary: Safari Networking high % CPU when Caches/WebKit/ServiceWorkers folder not writable
Product: WebKit Reporter: Jeff Johnson <opendarwin>
Component: Service WorkersAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, cdumez, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: Mac (Apple Silicon)   
OS: macOS 11   
Attachments:
Description Flags
Patch none

Description Jeff Johnson 2021-01-01 07:44:59 PST
When the Caches/WebKit/ServiceWorkers folder is not writable, the Safari Networking process has very high CPU usage (near 100%), due to logging error messages nonstop.

Steps to reproduce:
1) Delete the contents of the folder ~/Library/Containers/com.apple.Safari/Data/Library/Caches
2) Lock the folder ~/Library/Containers/com.apple.Safari/Data/Library/Caches in Finder
3) Launch Safari
4) Open https://www.youtube.com
5) Play a video
6) Launch Activity Monitor and view % CPU
7) Launch Console and view messages

I found the problem by also noticing the "logd" process high in Activity Monitor, which inspired me to check the Console log. I saw the following errors over and over again:

com.apple.WebKit.Networking	os_unix.c:44500: (2) open(/Users/bigsir/Library/Containers/com.apple.Safari/Data/Library/Caches/WebKit/ServiceWorkers/ServiceWorkerRegistrations-5.sqlite3) - No such file or directory
com.apple.WebKit.Networking	Failed to open Service Worker registration database
com.apple.WebKit.Networking	cannot open file at line 44499 of [02c344acea]

I've reproduced this issue with macOS 11.1 (20C69) and Safari 14.0.2 (16610.3.7.1.9) on an Apple silicon Mac mini, and also with macOS 10.14.6 (18G7016) on an Intel MacBook Pro.

I had locked the Safari Caches folder because it tends to get enormous on disk for no good reason. I don't need or want anything to be cached on disk after I quit Safari.
Comment 1 Alexey Proskuryakov 2021-01-02 10:44:52 PST
I think that this is something we'd consider to be unsupported configuration, but CC'ing other folks for their perspectives.
Comment 2 youenn fablet 2021-01-04 07:59:04 PST
> I had locked the Safari Caches folder because it tends to get enormous on
> disk for no good reason. I don't need or want anything to be cached on disk
> after I quit Safari.

Why not using Safari private windows?
Comment 3 youenn fablet 2021-01-04 07:59:38 PST
(In reply to Alexey Proskuryakov from comment #1)
> I think that this is something we'd consider to be unsupported
> configuration, but CC'ing other folks for their perspectives.

I tend to agree, though it should not be too difficult to fix.
Comment 4 Jeff Johnson 2021-01-04 08:14:51 PST
> Why not using Safari private windows?

Some people including myself would like private browsing by default. However, Safari has several barriers to this. For example, there is no Private Window option in the "New windows open with" preference. Also, the ⌘n keyboard shortcut cannot be successfully redefined to New Private Window in System Preferences, Keyboard, Shortcuts.

> it should not be too difficult to fix.

This was the hope. It may be unsupported, but perhaps this bug reveals that the architecture of the underlying code is a bit problematic.
Comment 5 Radar WebKit Bug Importer 2021-01-08 07:45:23 PST
<rdar://problem/72930195>
Comment 6 youenn fablet 2021-01-08 08:35:20 PST
Created attachment 417268 [details]
Patch
Comment 7 youenn fablet 2021-01-12 05:29:25 PST
Comment on attachment 417268 [details]
Patch

test failure is unrelated
Comment 8 EWS 2021-01-12 09:00:25 PST
Committed r271404: <https://trac.webkit.org/changeset/271404>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417268 [details].