Bug 240981

Summary: Move disk operations when deleting cookies off from the main thread
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: WebKit Misc.Assignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, ews-watchlist, hi, japhet, joepeck, pangle, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch achristensen: review-, ews-feeder: commit-queue-

Description Alex Christensen 2022-05-26 14:56:46 PDT
When it's on the main thread, it causes hangs and lack of responsiveness.
Comment 1 Alex Christensen 2022-05-26 15:00:14 PDT
https://github.com/WebKit/WebKit/pull/1072
Comment 2 Alex Christensen 2022-05-26 15:07:03 PDT
Created attachment 459795 [details]
Patch
Comment 3 Chris Dumez 2022-05-26 15:13:29 PDT
Comment on attachment 459795 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459795&action=review

> Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:155
> +            [nsCookieStorage() setCookie:newCookie];

Isn't this doing a cookie storage operation on the main thread?

> Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:585
> +        [nsCookieStorage() _saveCookies:makeBlockPtr([completionHandler = WTFMove(completionHandler)] () mutable {

Isn't this doing cookie operations on the main thread?

> Source/WebKit/NetworkProcess/Cookies/WebCookieManager.h:76
> +    void deleteAllCookies(PAL::SessionID, CompletionHandler<void()>&&);

I wish you'd use `CompletionHandler<void()>&&` consistently in your patch. However, you're using `CompletionHandler<void()>` as parameter sometimes.
Comment 4 Alex Christensen 2022-05-26 15:19:25 PDT
(In reply to Chris Dumez from comment #3)
> Comment on attachment 459795 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=459795&action=review
> 
> > Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:155
> > +            [nsCookieStorage() setCookie:newCookie];
> 
> Isn't this doing a cookie storage operation on the main thread?
I think setting a cookie doesn't always immediately go to disk on the same thread.  This patch only addresses cookie deleting on the main thread.

> > Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:585
> > +        [nsCookieStorage() _saveCookies:makeBlockPtr([completionHandler = WTFMove(completionHandler)] () mutable {
> 
> Isn't this doing cookie operations on the main thread?
Ditto.

> > Source/WebKit/NetworkProcess/Cookies/WebCookieManager.h:76
> > +    void deleteAllCookies(PAL::SessionID, CompletionHandler<void()>&&);
> 
> I wish you'd use `CompletionHandler<void()>&&` consistently in your patch.
> However, you're using `CompletionHandler<void()>` as parameter sometimes.
I'm trying to move to without && but there were places where it looked out of place.  The two are functionally equivalent.
Comment 5 Chris Dumez 2022-05-26 15:22:25 PDT
(In reply to Alex Christensen from comment #4)
> (In reply to Chris Dumez from comment #3)
> > Comment on attachment 459795 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=459795&action=review
> > 
> > > Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:155
> > > +            [nsCookieStorage() setCookie:newCookie];
> > 
> > Isn't this doing a cookie storage operation on the main thread?
> I think setting a cookie doesn't always immediately go to disk on the same
> thread.  This patch only addresses cookie deleting on the main thread.
> 
> > > Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:585
> > > +        [nsCookieStorage() _saveCookies:makeBlockPtr([completionHandler = WTFMove(completionHandler)] () mutable {
> > 
> > Isn't this doing cookie operations on the main thread?
> Ditto.
> 
> > > Source/WebKit/NetworkProcess/Cookies/WebCookieManager.h:76
> > > +    void deleteAllCookies(PAL::SessionID, CompletionHandler<void()>&&);
> > 
> > I wish you'd use `CompletionHandler<void()>&&` consistently in your patch.
> > However, you're using `CompletionHandler<void()>` as parameter sometimes.
> I'm trying to move to without && but there were places where it looked out
> of place.  The two are functionally equivalent.

CompletionHandler<void()>&& communicates to the caller that we want a r-value and they need to WTFMove(). CompletionHandler<void()> doesn't communicate that. It will give a build time error though if they fail to WTFMove() (only because CompletionHandler is not copyable).
Comment 6 Alex Christensen 2022-05-26 15:41:47 PDT
Comment on attachment 459795 [details]
Patch

GitHub PR has more &&
Comment 7 EWS 2022-05-27 12:21:15 PDT
Committed r294947 (251055@main): <https://commits.webkit.org/251055@main>

Reviewed commits have been landed. Closing PR #1072 and removing active labels.
Comment 8 Radar WebKit Bug Importer 2022-05-27 12:22:14 PDT
<rdar://problem/94048443>