Bug 131478 - Move early return out of dispatch_async() block so we can return from willSendRequest quickly
Summary: Move early return out of dispatch_async() block so we can return from willSen...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Pratik Solanki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-04-09 23:28 PDT by Pratik Solanki
Modified: 2014-04-13 12:20 PDT (History)
4 users (show)

See Also:


Attachments
Patch (2.96 KB, patch)
2014-04-09 23:32 PDT, Pratik Solanki
no flags Details | Formatted Diff | Diff
Patch (4.58 KB, patch)
2014-04-10 16:04 PDT, Pratik Solanki
ap: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pratik Solanki 2014-04-09 23:28:20 PDT
Move early return out of dispatch_async() block so we can return from willSendRequest quickly
Comment 1 Pratik Solanki 2014-04-09 23:32:19 PDT
Created attachment 229025 [details]
Patch
Comment 2 Pratik Solanki 2014-04-09 23:32:56 PDT
<rdar://problem/16575535>
Comment 3 Alexey Proskuryakov 2014-04-09 23:49:30 PDT
Comment on attachment 229025 [details]
Patch

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

> Source/WebCore/ChangeLog:9
> +        We can do a check for redirect response on the dispatch queue and return from willSendRequest

synthesizeRedirectResponseIfNecessary uses ResourceRequest class, which is not thread safe. The Foundation version of this function doesn't do that, so it's safe to call on a secondary thread.

Good catch though, perhaps we can refactor the code to make this fix work.
Comment 4 Pratik Solanki 2014-04-10 16:04:39 PDT
Created attachment 229084 [details]
Patch
Comment 5 Pratik Solanki 2014-04-10 16:09:12 PDT
(In reply to comment #4)
> Created an attachment (id=229084) [details]
> Patch

Maybe something like this would work? We save the scheme from the request and do a quick comparison and early return if they match.
Comment 6 Alexey Proskuryakov 2014-04-10 17:30:32 PDT
Comment on attachment 229084 [details]
Patch

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

I'm not sure if we need to follow the Mac pattern with secondary threads at all - it looks like CFURLConnection may have all the async delegates we could wish for.

If that's feasible, that should be much better, and would make this patch unnecessary.

> Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:86
> +    if (!originalRedirectResponse) {
> +        RetainPtr<CFStringRef> newScheme = adoptCF(CFURLCopyScheme(CFURLRequestGetURL(cfRequest)));
> +        if (CFStringCompare(newScheme.get(), m_originalScheme.get(), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
> +            CFRetain(cfRequest);
> +            return cfRequest;
> +        }
> +    }

Shouldn't this code be removed from synthesizeRedirectResponseIfNecessary() now?

Would also be good to move a comment about HSTS here.
Comment 7 Pratik Solanki 2014-04-10 18:04:34 PDT
Comment on attachment 229084 [details]
Patch

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

>> Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:86
>> +    }
> 
> Shouldn't this code be removed from synthesizeRedirectResponseIfNecessary() now?
> 
> Would also be good to move a comment about HSTS here.

Yes, I can remove the code from synthesizeRedirectResponseIfNecessary() and I'll addd a comment.
Comment 8 Pratik Solanki 2014-04-10 22:05:10 PDT
(In reply to comment #6)
> (From update of attachment 229084 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=229084&action=review
> 
> I'm not sure if we need to follow the Mac pattern with secondary threads at all - it looks like CFURLConnection may have all the async delegates we could wish for.
> 
> If that's feasible, that should be much better, and would make this patch unnecessary.

I'll take a look at this next.
Comment 9 Pratik Solanki 2014-04-13 12:18:24 PDT
(In reply to comment #7)
> (From update of attachment 229084 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=229084&action=review
> 
> >> Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:86
> >> +    }
> > 
> > Shouldn't this code be removed from synthesizeRedirectResponseIfNecessary() now?
> > 
> > Would also be good to move a comment about HSTS here.
> 
> Yes, I can remove the code from synthesizeRedirectResponseIfNecessary() and I'll addd a comment.

SynchronousResourceHandleCFURLConnectionDelegate::willSendRequest() calls synthesizeRedirectResponseIfNecessary() as well so I can't remove the code. I'll leave it in for now.
Comment 10 Pratik Solanki 2014-04-13 12:20:51 PDT
Committed r167200: <http://trac.webkit.org/changeset/167200>