Bug 203934 - Re-enable NSURLSession isolation after r252116
Summary: Re-enable NSURLSession isolation after r252116
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-11-06 17:26 PST by Alex Christensen
Modified: 2019-11-07 09:05 PST (History)
7 users (show)

See Also:


Attachments
Patch (58.97 KB, patch)
2019-11-06 17:35 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (58.89 KB, patch)
2019-11-06 18:21 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (62.31 KB, patch)
2019-11-06 18:37 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (62.81 KB, patch)
2019-11-06 19:00 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (62.89 KB, patch)
2019-11-07 06:29 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (65.99 KB, patch)
2019-11-07 07:34 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (65.93 KB, patch)
2019-11-07 08:37 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (66.05 KB, patch)
2019-11-07 08:48 PST, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2019-11-06 17:26:40 PST
Re-enable NSURLSession isolation after r252116
Comment 1 Alex Christensen 2019-11-06 17:35:43 PST
Created attachment 382991 [details]
Patch
Comment 2 Alex Christensen 2019-11-06 17:35:49 PST
<rdar://problem/56921584>
Comment 3 John Wilander 2019-11-06 17:59:03 PST
Comment on attachment 382991 [details]
Patch

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

Nice! See my comments. I'd like someone else to have a look to, who's more familiar with task identifiers.

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:122
> +    SessionWrapper m_ephemeralStatelessSession;

To make sure I understand, you're changing it so that stateless is now WithoutCredentialStorage and ephemeralStatelessCookieless is now ephemeralStateless?

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:544
> +            ASSERT_NOT_REACHED();

This we need to test manually after you land since layout tests don't support HSTS.

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:1140
> +    m_ephemeralStatelessSession.initialize(configuration, *this, WebCore::StoredCredentialsPolicy::EphemeralStatelessCookieless);

Maybe we should rename StoredCredentialsPolicy::EphemeralStatelessCookieless to StoredCredentialsPolicy::EphemeralStateless to match the member naming?

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:1144
>  {

#if ENABLE(RESOURCE_LOAD_STATISTICS)

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:1150
> +        ASSERT_NOT_REACHED();

#endif
Comment 4 Chris Dumez 2019-11-06 17:59:36 PST
I refactored this code quite a bit after the huge regression so your patch definitely will not apply.
Comment 5 Alex Christensen 2019-11-06 18:21:18 PST
Created attachment 382999 [details]
Patch
Comment 6 Alex Christensen 2019-11-06 18:26:48 PST
(In reply to John Wilander from comment #3)
> Comment on attachment 382991 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=382991&action=review
> 
> Nice! See my comments. I'd like someone else to have a look to, who's more
> familiar with task identifiers.
> 
> > Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:122
> > +    SessionWrapper m_ephemeralStatelessSession;
> 
> To make sure I understand, you're changing it so that stateless is now
> WithoutCredentialStorage and ephemeralStatelessCookieless is now
> ephemeralStateless?
Correct.  Stateless implies cookieless, and what we called "stateless" before was leftover from when we tried to make it actually stateless and learned that it needs to be just without credentials.
Comment 7 Alex Christensen 2019-11-06 18:37:51 PST
Created attachment 383002 [details]
Patch
Comment 8 Alex Christensen 2019-11-06 19:00:00 PST
Created attachment 383004 [details]
Patch
Comment 9 Chris Dumez 2019-11-06 21:03:47 PST
Comment on attachment 383004 [details]
Patch

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

> Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:76
> +    cocoaSession.m_sessionWithCredentialStorage.downloadMap.add(taskIdentifier, m_downloadID);

I think we should avoid interacting with network session data members directly, this is bad practice.

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:66
> +    friend class Download;

Let's avoid this. I think we should strive to remove friends, not add more.
Comment 10 Chris Dumez 2019-11-06 21:11:02 PST
Comment on attachment 383004 [details]
Patch

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

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:54
> +    WeakPtr<NetworkSessionCocoa> sessionCocoa;

Including this here seems wasteful:
- NetworkDataTaskCocoa already has access to this via m_session.
- This IsolatedSession struct has 2 SessionWrapper members, so ends up with 2 identical pointers to the NetworkSessionCocoa.

I think we should extra this member out.
Comment 11 Chris Dumez 2019-11-06 21:14:51 PST
Comment on attachment 383004 [details]
Patch

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

>> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:54
>> +    WeakPtr<NetworkSessionCocoa> sessionCocoa;
> 
> Including this here seems wasteful:
> - NetworkDataTaskCocoa already has access to this via m_session.
> - This IsolatedSession struct has 2 SessionWrapper members, so ends up with 2 identical pointers to the NetworkSessionCocoa.
> 
> I think we should extra this member out.

No to mention that the NetworkSessionCocoa has these data members:
SessionWrapper m_sessionWithCredentialStorage;
SessionWrapper m_sessionWithoutCredentialStorage;
SessionWrapper m_ephemeralStatelessSession;

So ends up with 3 unnecessary WeakPtrs to itself.
Comment 12 Chris Dumez 2019-11-06 21:24:45 PST
Comment on attachment 383004 [details]
Patch

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

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:537
> +        if (auto sessionCocoa = _sessionWrapper ? _sessionWrapper->sessionCocoa.get() : nullptr) {

Could use [self sessionCocoa].

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:573
> +        if (auto sessionCocoa = _sessionWrapper ? _sessionWrapper->sessionCocoa.get() : nullptr) {

Could use [self sessionCocoa].

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:897
> +    ASSERT(!_sessionWrapper->downloadMap.contains(downloadTask.taskIdentifier));

RELEASE_ASSERT ?

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:1370
> +    ASSERT(!m_sessionWithCredentialStorage.webSocketDataTaskMap.contains(task.identifier()));

RELEASE_ASSERT?

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:1376
> +    ASSERT(m_sessionWithCredentialStorage.webSocketDataTaskMap.contains(task.identifier()));

RELEASE_ASSERT?
Comment 13 Alex Christensen 2019-11-07 06:22:35 PST
Comment on attachment 383004 [details]
Patch

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

>>> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:54
>>> +    WeakPtr<NetworkSessionCocoa> sessionCocoa;
>> 
>> Including this here seems wasteful:
>> - NetworkDataTaskCocoa already has access to this via m_session.
>> - This IsolatedSession struct has 2 SessionWrapper members, so ends up with 2 identical pointers to the NetworkSessionCocoa.
>> 
>> I think we should extra this member out.
> 
> No to mention that the NetworkSessionCocoa has these data members:
> SessionWrapper m_sessionWithCredentialStorage;
> SessionWrapper m_sessionWithoutCredentialStorage;
> SessionWrapper m_ephemeralStatelessSession;
> 
> So ends up with 3 unnecessary WeakPtrs to itself.

These WeakPtrs are actually necessary right now to get from the download delegate callbacks to the NetworkSession because Downloads are owned by the DownloadManager and only have an identifier, no reference to their NetworkSession.  We could fix this in a further refactoring, but I think that should not be in the same patch as the rest of this.  I'll put a fixme for now.
Comment 14 Alex Christensen 2019-11-07 06:29:30 PST
Created attachment 383043 [details]
Patch
Comment 15 Chris Dumez 2019-11-07 06:53:33 PST
(In reply to Alex Christensen from comment #13)
> Comment on attachment 383004 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=383004&action=review
> 
> >>> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h:54
> >>> +    WeakPtr<NetworkSessionCocoa> sessionCocoa;
> >> 
> >> Including this here seems wasteful:
> >> - NetworkDataTaskCocoa already has access to this via m_session.
> >> - This IsolatedSession struct has 2 SessionWrapper members, so ends up with 2 identical pointers to the NetworkSessionCocoa.
> >> 
> >> I think we should extra this member out.
> > 
> > No to mention that the NetworkSessionCocoa has these data members:
> > SessionWrapper m_sessionWithCredentialStorage;
> > SessionWrapper m_sessionWithoutCredentialStorage;
> > SessionWrapper m_ephemeralStatelessSession;
> > 
> > So ends up with 3 unnecessary WeakPtrs to itself.
> 
> These WeakPtrs are actually necessary right now to get from the download
> delegate callbacks to the NetworkSession because Downloads are owned by the
> DownloadManager and only have an identifier, no reference to their
> NetworkSession.  We could fix this in a further refactoring, but I think
> that should not be in the same patch as the rest of this.  I'll put a fixme
> for now.

Whoever needs it, can store it separately. It does not need and should not be in this structure.
Comment 16 Chris Dumez 2019-11-07 06:58:21 PST
Comment on attachment 383043 [details]
Patch

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

> Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:73
> +    m_downloadTask = [cocoaSession.sessionWrapperForDownloads().session downloadTaskWithResumeData:updatedData];

Download seems to have access to its session here, so what do you mean?

I don’t think there is a rush to re-land me so I do not understand the need to land a FIXME.
Comment 17 Alex Christensen 2019-11-07 07:34:44 PST
Created attachment 383046 [details]
Patch
Comment 18 Alex Christensen 2019-11-07 08:05:23 PST
(In reply to Chris Dumez from comment #16)
> Comment on attachment 383043 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=383043&action=review
> 
> > Source/WebKit/NetworkProcess/Downloads/cocoa/DownloadCocoa.mm:73
> > +    m_downloadTask = [cocoaSession.sessionWrapperForDownloads().session downloadTaskWithResumeData:updatedData];
> 
> Download seems to have access to its session here, so what do you mean?
Once we have a Download that's easy.  It's getting from the WKNetworkSessionDelegate to the Download that's hard because we only have a DownloadID, and the Downloads must be gotten through the DownloadManager right now.  I fixed it by adding a WeakPtr<NetworkProcess> in DownloadData that is made only when we make a Download and used only for Downloads.  I think that was a lot of work just to remove the 3-WeakPtr initialization cost addition to creating a NetworkSession (which is a heavy object).  I don't think it was worth that work right now, but it's done and ready for review again.
Comment 19 Chris Dumez 2019-11-07 08:24:13 PST
Comment on attachment 383046 [details]
Patch

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

> Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:399
> +    WeakPtr<WebKit::SessionWrapper> _sessionWrapper;

I think this should have a WeakPtr to the NetworkSessionCocoa and another WeakPtr to the sessionWrapper.
Then you can get the network process from the NetworkSessionCocoa, like we used to. And you don't need to have a WeakPtr to the NetworkProcess in the DownloadData.
Comment 20 Alex Christensen 2019-11-07 08:37:39 PST
Created attachment 383053 [details]
Patch
Comment 21 Chris Dumez 2019-11-07 08:38:58 PST
Comment on attachment 383053 [details]
Patch

r=me
Comment 22 Alex Christensen 2019-11-07 08:48:45 PST
Created attachment 383054 [details]
Patch
Comment 23 Alex Christensen 2019-11-07 09:05:41 PST
http://trac.webkit.org/r252185