Skip to content

[Site Isolation] Fix TestWebKitAPI.WKWebsiteDataStore.* tests#69419

Draft
szewai wants to merge 1 commit into
WebKit:mainfrom
szewai:eng/Site-Isolation-Fix-TestWebKitAPI-WKWebsiteDataStore-tests
Draft

[Site Isolation] Fix TestWebKitAPI.WKWebsiteDataStore.* tests#69419
szewai wants to merge 1 commit into
WebKit:mainfrom
szewai:eng/Site-Isolation-Fix-TestWebKitAPI-WKWebsiteDataStore-tests

Conversation

@szewai

@szewai szewai commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

b8ecb32

[Site Isolation] Fix TestWebKitAPI.WKWebsiteDataStore.* tests
https://bugs.webkit.org/show_bug.cgi?id=319420
rdar://182245093

Reviewed by NOBODY (OOPS!).

Tests like WKWebsiteDataStore.ListIdentifiers is failing under Site Isolation because WebProcessProxy is still alive
after WebPageProxy is closed, holding WebsiteDataStore and thus NetworkProcessProxy alive. This is a leak because
web process or network process should exit when clients close all WKWebViews.

Investigation indicates the reference chain is:
AudioHardwareListener / AudioSession => RemoteMediaSessionManagerProxy => WebProcessProxy.
So the bug is RemoteMediaSessionManagerProxy registers itself as global singleton AudioSession::sharedAudioSession()
(which is a strong ref) when is is being created by WebPageProxy, but it does not clear the reference when WebPageProxy
is closed. This causes leakage of WebProcessProxy (and other objects) as RemoteMediaSessionManagerProxy holds strong
ref to WebProcessProxy.

To fix this leak, add AudioSession::clearSharedSession() and call it from a new
RemoteMediaSessionManagerProxy::invalidate(), which runs both from the destructor and from WebPageProxy::resetState()
when the manager is torn down ahead of a process swap, breaking the cycle before the swap can strand a live process
reference.

Also, stop caching a strong Ref<WebProcessProxy> in RemoteMediaSessionManagerProxy and instead derive the process on
demand from the page's WeakPtr, matching how the sibling proxies (WebFullScreenManagerProxy,
VideoPresentationManagerProxy, PlaybackSessionManagerProxy) already do it. This removes the last strong ref to
WebProcessProxy the manager was holding.

* Source/WebCore/platform/audio/AudioSession.cpp:
(WebCore::AudioSession::clearSharedSession):
* Source/WebCore/platform/audio/AudioSession.h:
* Source/WebKit/UIProcess/Media/RemoteMediaSessionManagerProxy.cpp:
(WebKit::currentAudioHardwareListenerCreator):
(WebKit::RemoteMediaSessionManagerProxy::RemoteMediaSessionManagerProxy):
(WebKit::RemoteMediaSessionManagerProxy::~RemoteMediaSessionManagerProxy):
(WebKit::RemoteMediaSessionManagerProxy::invalidate):
(WebKit::RemoteMediaSessionManagerProxy::process const):
(WebKit::RemoteMediaSessionManagerProxy::messageSenderConnection const):
(WebKit::RemoteMediaSessionManagerProxy::sharedPreferencesForWebProcess const):
* Source/WebKit/UIProcess/Media/RemoteMediaSessionManagerProxy.h:
(WebKit::RemoteMediaSessionManagerProxy::process const): Deleted.
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::resetState):

b8ecb32

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe loading 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ⏳ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
loading 🛠 ios-safer-cpp loading 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 api-gtk
✅ 🛠 vision-sim ⏳ 🧪 mac-intel-wk2 ⏳ 🛠 playstation
✅ 🧪 vision-wk2 ❌ 🛠 mac-safer-cpp
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

https://bugs.webkit.org/show_bug.cgi?id=319420
rdar://182245093

Reviewed by NOBODY (OOPS!).

Tests like WKWebsiteDataStore.ListIdentifiers is failing under Site Isolation because WebProcessProxy is still alive
after WebPageProxy is closed, holding WebsiteDataStore and thus NetworkProcessProxy alive. This is a leak because
web process or network process should exit when clients close all WKWebViews.

Investigation indicates the reference chain is:
AudioHardwareListener / AudioSession => RemoteMediaSessionManagerProxy => WebProcessProxy.
So the bug is RemoteMediaSessionManagerProxy registers itself as global singleton AudioSession::sharedAudioSession()
(which is a strong ref) when is is being created by WebPageProxy, but it does not clear the reference when WebPageProxy
is closed. This causes leakage of WebProcessProxy (and other objects) as RemoteMediaSessionManagerProxy holds strong
ref to WebProcessProxy.

To fix this leak, add AudioSession::clearSharedSession() and call it from a new
RemoteMediaSessionManagerProxy::invalidate(), which runs both from the destructor and from WebPageProxy::resetState()
when the manager is torn down ahead of a process swap, breaking the cycle before the swap can strand a live process
reference.

Also, stop caching a strong Ref<WebProcessProxy> in RemoteMediaSessionManagerProxy and instead derive the process on
demand from the page's WeakPtr, matching how the sibling proxies (WebFullScreenManagerProxy,
VideoPresentationManagerProxy, PlaybackSessionManagerProxy) already do it. This removes the last strong ref to
WebProcessProxy the manager was holding.

* Source/WebCore/platform/audio/AudioSession.cpp:
(WebCore::AudioSession::clearSharedSession):
* Source/WebCore/platform/audio/AudioSession.h:
* Source/WebKit/UIProcess/Media/RemoteMediaSessionManagerProxy.cpp:
(WebKit::currentAudioHardwareListenerCreator):
(WebKit::RemoteMediaSessionManagerProxy::RemoteMediaSessionManagerProxy):
(WebKit::RemoteMediaSessionManagerProxy::~RemoteMediaSessionManagerProxy):
(WebKit::RemoteMediaSessionManagerProxy::invalidate):
(WebKit::RemoteMediaSessionManagerProxy::process const):
(WebKit::RemoteMediaSessionManagerProxy::messageSenderConnection const):
(WebKit::RemoteMediaSessionManagerProxy::sharedPreferencesForWebProcess const):
* Source/WebKit/UIProcess/Media/RemoteMediaSessionManagerProxy.h:
(WebKit::RemoteMediaSessionManagerProxy::process const): Deleted.
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::resetState):
@szewai szewai self-assigned this Jul 14, 2026
@szewai szewai added the New Bugs Unclassified bugs are placed in this component until the correct component can be determined. label Jul 14, 2026
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #120889 (b8ecb32)

❌ Found 1 failing file with 3 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merging-blocked Applied to prevent a change from being merged New Bugs Unclassified bugs are placed in this component until the correct component can be determined.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants