Bug 150355 - Initial NSURLSession WebResourceLoader implementation
Summary: Initial NSURLSession WebResourceLoader implementation
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:
Depends on:
Blocks: 150834
  Show dependency treegraph
 
Reported: 2015-10-19 22:07 PDT by Alex Christensen
Modified: 2015-11-02 21:59 PST (History)
4 users (show)

See Also:


Attachments
Patch (38.03 KB, patch)
2015-10-19 22:09 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (38.73 KB, patch)
2015-10-19 22:32 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (39.00 KB, patch)
2015-10-20 10:38 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (39.00 KB, patch)
2015-10-20 10:38 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (37.73 KB, patch)
2015-10-21 14:41 PDT, Alex Christensen
koivisto: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2015-10-19 22:07:11 PDT
Initial NSURLSession WebResourceLoader implementation
Comment 1 Alex Christensen 2015-10-19 22:09:46 PDT
Created attachment 263551 [details]
Patch
Comment 2 Alex Christensen 2015-10-19 22:32:43 PDT
Created attachment 263553 [details]
Patch
Comment 3 Alex Christensen 2015-10-20 10:38:27 PDT
Created attachment 263588 [details]
Patch
Comment 4 Alex Christensen 2015-10-20 10:38:58 PDT
Created attachment 263589 [details]
Patch
Comment 5 Alex Christensen 2015-10-20 13:50:35 PDT
1560 tests ran as expected, 347 didn't:
Unexpected flakiness: text-only failures (212)
Unexpected flakiness: image-only failures (8)
Unexpected flakiness: timeouts (79)
Regressions: Unexpected text-only failures (2)
Regressions: Unexpected crashes (46)

So, a pretty good start.
Comment 6 Alexey Proskuryakov 2015-10-20 22:20:01 PDT
Comment on attachment 263589 [details]
Patch

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

> Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp:290
> +    

Blank line here.

> Source/WebKit2/NetworkProcess/NetworkingSession.h:74
> +    virtual ~NetworkingDataTaskClient() { };

The semicolon is not needed here.

> Source/WebKit2/NetworkProcess/cocoa/NetworkingSessionCocoa.mm:135
> +            WebCore::ResourceResponse resourceResponse(response);

Please add ASSERT(isMainThread()) in all functions that touch ResourceRequest or ResourceResponse. These classes are not safe to use from secondary threads.

> Source/WebKit2/NetworkProcess/cocoa/NetworkingSessionCocoa.mm:150
> +        // FIXME: Look into why this being on the main thread causes fewer crashes, but more crashes with the other callbacks.

:-/

> Source/WebKit2/NetworkProcess/cocoa/NetworkingSessionCocoa.mm:190
> +    m_session = [NSURLSession sessionWithConfiguration:configuration delegate:static_cast<id>(m_sessionDelegate.get()) delegateQueue:m_sessionQueue.get()];

Hmm, don't we want to have delegates called on main thread? Why is there a queue at all?
Comment 7 Antti Koivisto 2015-10-21 06:37:32 PDT
Comment on attachment 263589 [details]
Patch

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

> Source/WebKit2/NetworkProcess/NetworkResourceLoader.h:123
> +#if !USE(NSURLSESSION)
>      const WebCore::ResourceResponse& response() const { return m_response; }
> +#endif

Why #if out m_response? It is going to be needed eventually and should be readily available already.

> Source/WebKit2/NetworkProcess/NetworkingSession.h:64
> +class NetworkingSession;

Why "Networking" instead of "Network" like other network process classes?

> Source/WebKit2/NetworkProcess/NetworkingSession.h:77
> +class NetworkingDataTask : public RefCounted<NetworkingDataTask> {

Maybe use "NetworkSession" as namespace for these related types, NetworkSessionDataTask or just NetworkSessionTask? (what kind of other tasks are there going to be?)

similarly NetworkingDataTaskClient -> NetworkSessionTaskClient?

> Source/WebKit2/NetworkProcess/NetworkingSession.h:111
> +    ~NetworkingSession() { LockHolder locker(m_dataTaskMapLock); ASSERT(m_dataTaskMap.isEmpty()); }

This locker doesn't do anything useful in non-debug builds and shouldn't be necessary in debug builds either.

> Source/WebKit2/NetworkProcess/cocoa/NetworkingSessionCocoa.mm:93
> +    if (auto networkingTask = _session->dataTaskForIdentifier(task.taskIdentifier)) {

Please use auto* for pointer types: auto* networkingTask

> Source/WebKit2/NetworkProcess/cocoa/NetworkingSessionCocoa.mm:94
> +        if (auto client = networkingTask->client()) {

Please use auto* for pointer types: auto* client

etc everywhere in this patch.

>> Source/WebKit2/NetworkProcess/cocoa/NetworkingSessionCocoa.mm:150
>> +        // FIXME: Look into why this being on the main thread causes fewer crashes, but more crashes with the other callbacks.
> 
> :-/

The threading story seems bit shaky. Can we just make callbacks in the main thread for the first iteration?
Comment 8 Alex Christensen 2015-10-21 10:24:52 PDT
Comment on attachment 263589 [details]
Patch

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

>> Source/WebKit2/NetworkProcess/NetworkResourceLoader.h:123
>> +#endif
> 
> Why #if out m_response? It is going to be needed eventually and should be readily available already.

Aha!  I was copying it on a non-main thread, and I was seeing AtomicString assertion failures.  I need to copy on the main thread, then I won't need to get rid of m_response.
Comment 9 Antti Koivisto 2015-10-21 13:29:32 PDT
Comment on attachment 263589 [details]
Patch

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

> Source/WebKit2/config.h:76
> +#ifndef USE_NSURLSESSION

This should probably be something like USE_NETWORK_SESSION. The layer covered by this is not platform specific (though the implementation is).
Comment 10 Alex Christensen 2015-10-21 14:21:57 PDT
(In reply to comment #6)
> > Source/WebKit2/NetworkProcess/cocoa/NetworkingSessionCocoa.mm:190
> > +    m_session = [NSURLSession sessionWithConfiguration:configuration delegate:static_cast<id>(m_sessionDelegate.get()) delegateQueue:m_sessionQueue.get()];
> 
> Hmm, don't we want to have delegates called on main thread? Why is there a
> queue at all?
My next patch will use [NSOperationQueue mainQueue] to put all the callbacks on the main thread.  And I replace the lock with ASSERT(isMainThread());
Comment 11 Alex Christensen 2015-10-21 14:41:32 PDT
Created attachment 263741 [details]
Patch
Comment 12 Antti Koivisto 2015-10-22 09:28:51 PDT
Comment on attachment 263741 [details]
Patch

r=me
Comment 13 Alex Christensen 2015-10-22 11:01:24 PDT
http://trac.webkit.org/changeset/191457