Bug 163939

Summary: NetworkSession: Add NetworkDataTask implementation for blobs
Product: WebKit Reporter: Carlos Garcia Campos <cgarcia>
Component: WebKit2Assignee: Carlos Garcia Campos <cgarcia>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, aestes, beidson, cdumez, krollin
Priority: P2    
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=164458
Attachments:
Description Flags
WIP patch
none
Builds macOS and iOS, passes fast layout tests, loads various pages.
none
Patch
buildbot: commit-queue-
Archive of layout-test-results from ews126 for ios-simulator-wk2
none
Try to fix mac builds
none
Try to fix failing tests
achristensen: review-
Updated patch including logs
none
Patch
none
Patch for landing
none
Updated patch for landing none

Carlos Garcia Campos
Reported 2016-10-25 05:53:36 PDT
And get rid of ResourceHandle in NetworkProcess when NetworkSession is enabled.
Attachments
WIP patch (61.93 KB, patch)
2016-10-25 05:56 PDT, Carlos Garcia Campos
no flags
Builds macOS and iOS, passes fast layout tests, loads various pages. (11.60 KB, patch)
2016-10-27 23:07 PDT, Keith Rollin
no flags
Patch (81.14 KB, patch)
2016-10-29 02:23 PDT, Carlos Garcia Campos
buildbot: commit-queue-
Archive of layout-test-results from ews126 for ios-simulator-wk2 (deleted)
2016-10-29 03:51 PDT, Build Bot
no flags
Try to fix mac builds (82.21 KB, patch)
2016-10-30 00:10 PDT, Carlos Garcia Campos
no flags
Try to fix failing tests (82.31 KB, patch)
2016-10-30 01:11 PDT, Carlos Garcia Campos
achristensen: review-
Updated patch including logs (83.07 KB, patch)
2016-11-01 04:05 PDT, Carlos Garcia Campos
no flags
Patch (83.42 KB, patch)
2016-11-01 17:21 PDT, Alex Christensen
no flags
Patch for landing (84.31 KB, patch)
2016-11-02 02:59 PDT, Carlos Garcia Campos
no flags
Updated patch for landing (84.49 KB, patch)
2016-11-04 03:06 PDT, Carlos Garcia Campos
no flags
Carlos Garcia Campos
Comment 1 2016-10-25 05:56:59 PDT
Created attachment 292747 [details] WIP patch This is a WIP patch, it just needs to update XCode file to add the new files, and deal with iOS build failures.
Carlos Garcia Campos
Comment 2 2016-10-26 22:31:33 PDT
Could you guys help me with the xcode changes so that I can continue working on this, please?
Keith Rollin
Comment 3 2016-10-27 17:09:35 PDT
I'll work on it later tonight. I'll try to have something by 9:00 your time.
Carlos Garcia Campos
Comment 4 2016-10-27 22:49:27 PDT
(In reply to comment #3) > I'll work on it later tonight. I'll try to have something by 9:00 your time. Thanks! note that I'm not asking you to make it build, just to include the files, I'll fight with EWS.
Keith Rollin
Comment 5 2016-10-27 23:07:41 PDT
Created attachment 293118 [details] Builds macOS and iOS, passes fast layout tests, loads various pages.
Carlos Garcia Campos
Comment 6 2016-10-29 02:23:35 PDT
Build Bot
Comment 7 2016-10-29 03:50:56 PDT
Comment on attachment 293287 [details] Patch Attachment 293287 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/2398618 New failing tests: imported/w3c/web-platform-tests/XMLHttpRequest/send-redirect-bogus-sync.htm http/tests/xmlhttprequest/access-control-and-redirects.html http/tests/xmlhttprequest/xmlhttprequest-unsafe-redirect.html imported/w3c/web-platform-tests/XMLHttpRequest/send-redirect-infinite-sync.htm imported/w3c/web-platform-tests/XMLHttpRequest/xmlhttprequest-network-error-sync.htm
Build Bot
Comment 8 2016-10-29 03:51:00 PDT
Created attachment 293288 [details] Archive of layout-test-results from ews126 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews126 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.6
Carlos Garcia Campos
Comment 9 2016-10-30 00:10:30 PDT
Created attachment 293336 [details] Try to fix mac builds
Carlos Garcia Campos
Comment 10 2016-10-30 01:11:38 PDT
Created attachment 293337 [details] Try to fix failing tests I messed it up in the NetworkLoad refactoring, confused because we were using ResourceHandle API (with null handle) in network session code branch.
Alex Christensen
Comment 11 2016-10-31 08:41:25 PDT
Comment on attachment 293337 [details] Try to fix failing tests View in context: https://bugs.webkit.org/attachment.cgi?id=293337&action=review ! I'll have to review this from my Sierra machine and make sure things like the new blob downloads still work > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:77 > + , m_blobData(static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(request.url())) We should move away from using a global blob registry, but not in this patch. > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:206 > + // If the size is -1, it means the file has been moved or changed. Fail now. > + if (size == -1) { It would be nice if we could use Optional instead of having magic negative numbers. I know the blob code does things like this a lot, though. We need to clean that up. > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.h:48 > +class NetworkDataTaskBlob final : public NetworkDataTask, public WebCore::FileStreamClient { I think we should call this BlobDataTask, except it is used by a NetworkLoad. Blobs are weird.
Carlos Garcia Campos
Comment 12 2016-10-31 09:24:43 PDT
(In reply to comment #11) > Comment on attachment 293337 [details] > Try to fix failing tests > > View in context: > https://bugs.webkit.org/attachment.cgi?id=293337&action=review > > ! > I'll have to review this from my Sierra machine and make sure things like > the new blob downloads still work Great, thanks! I ran the anchor download tests that use blobs and they passed. > > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:77 > > + , m_blobData(static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(request.url())) > > We should move away from using a global blob registry, but not in this patch. I don't even know how that works, TBH. > > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:206 > > + // If the size is -1, it means the file has been moved or changed. Fail now. > > + if (size == -1) { > > It would be nice if we could use Optional instead of having magic negative > numbers. I know the blob code does things like this a lot, though. We need > to clean that up. That code is indeed copy-pasted from the ResourceHandle implementation, I tried to not change the existing code too much to avoid regressions, but I agree we can take advantage to do some small low risk cleanups. > > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.h:48 > > +class NetworkDataTaskBlob final : public NetworkDataTask, public WebCore::FileStreamClient { > > I think we should call this BlobDataTask, except it is used by a > NetworkLoad. Blobs are weird. I read this is as the NetworkDataTask implementation for Blobs.
Alex Christensen
Comment 13 2016-10-31 12:14:38 PDT
Comment on attachment 293337 [details] Try to fix failing tests View in context: https://bugs.webkit.org/attachment.cgi?id=293337&action=review >>> Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:77 >>> + , m_blobData(static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(request.url())) >> >> We should move away from using a global blob registry, but not in this patch. > > I don't even know how that works, TBH. Right now, blobRegistry() returns the global BlobRegistry, which is returned through PlatformStrategies. We need to remove PlatformStrategies::blobRegistry() and instead access the BlobRegistry through the NetworkSession, because it should be a member variable of the NetworkSession. Unfortunately, we need to keep the ResourceHandle code alive for another few years, and this development involves changing how the ResourceHandle registers a BlobResourceHandle constructor, adding SessionIDs in many places, and making some kind of map of SessionID to BlobRegistry just for ResourceHandles.
Alex Christensen
Comment 14 2016-10-31 12:27:42 PDT
This makes http/tests/security/anchor-download-allow-blob.html fail on Sierra as-is. Probably a minor modification.
Alex Christensen
Comment 15 2016-10-31 15:08:37 PDT
Comment on attachment 293337 [details] Try to fix failing tests View in context: https://bugs.webkit.org/attachment.cgi?id=293337&action=review I'm sure this is about 95% correct, but blobs and downloads don't work on Sierra and I'm not sure what's wrong. Chris wrote our blob download code. > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:258 > +void NetworkDataTaskBlob::didReceiveResponse(Error errorCode) Please add LOG(NetworkSession, ...) to each of these callbacks so they can actually be debugged. > Source/WebKit2/NetworkProcess/NetworkSession.h:64 > + HashSet<NetworkDataTask*> m_dataTaskSet; This is strange to have NetworkDataTaskBlobs kept in a set here on cocoa but not with Network-NetworkDataTasks. That might be the right thing to do, but I'm not sure.
Alex Christensen
Comment 16 2016-10-31 15:09:27 PDT
(In reply to comment #14) > This makes http/tests/security/anchor-download-allow-blob.html fail on > Sierra as-is. Probably a minor modification. It's not even creating a NetworkDataTaskBlob in this test.
Carlos Garcia Campos
Comment 17 2016-11-01 03:35:30 PDT
What failure are you getting? could you share the diff? It passes here: $ wktr http://127.0.0.1:8000/security/anchor-download-allow-blob.html Content-Type: text/plain Download started. Downloading URL with suggested filename "foo.pdf" Download completed. Tests that a suggested filename on a download attribute is allowed if the link is a blob URL. The suggested filename at the top should be foo.pdf. PASS successfullyParsed is true TEST COMPLETE #EOF #EOF #EOF
Carlos Garcia Campos
Comment 18 2016-11-01 03:42:54 PDT
(In reply to comment #12) > > > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:206 > > > + // If the size is -1, it means the file has been moved or changed. Fail now. > > > + if (size == -1) { > > > > It would be nice if we could use Optional instead of having magic negative > > numbers. I know the blob code does things like this a lot, though. We need > > to clean that up. > > That code is indeed copy-pasted from the ResourceHandle implementation, I > tried to not change the existing code too much to avoid regressions, but I > agree we can take advantage to do some small low risk cleanups. hmm, that -1 comes from FileStream::getSize(), I don't think we want to change that API in this patch.
Carlos Garcia Campos
Comment 19 2016-11-01 04:05:09 PDT
Created attachment 293547 [details] Updated patch including logs Added some log messages.
Alex Christensen
Comment 20 2016-11-01 15:55:12 PDT
Here's the diff. In this case, -999 is kCFURLErrorCancelled, which makes me think we are making a NetworkDataTask where we shouldn't be: --- /Users/alexchristensen/code/OpenSource/WebKitBuild/Debug/layout-test-results/http/tests/security/anchor-download-allow-blob-expected.txt +++ /Users/alexchristensen/code/OpenSource/WebKitBuild/Debug/layout-test-results/http/tests/security/anchor-download-allow-blob-actual.txt @@ -1,6 +1,7 @@ Download started. Downloading URL with suggested filename "foo.pdf" -Download completed. +Download failed. +Failed: NSURLErrorDomain, code=-999, description=cancelled Tests that a suggested filename on a download attribute is allowed if the link is a blob URL. The suggested filename at the top should be foo.pdf.
Alex Christensen
Comment 21 2016-11-01 15:58:53 PDT
And here are the logs: Created NetworkSession with cookieAcceptPolicy 2 1 Creating NetworkDataTask with URL http://127.0.0.1:8000/security/anchor-download-allow-blob.html 1 didReceiveResponse 1 didReceiveResponse completionHandler (cancel) 1 didCompleteWithError 2 Creating NetworkDataTask with URL http://127.0.0.1:8000/resources/js-test-pre.js 3 Creating NetworkDataTask with URL http://127.0.0.1:8000/resources/js-test-post.js 2 didReceiveResponse 2 didReceiveResponse completionHandler (cancel) 2 didCompleteWithError 3 didReceiveResponse 3 didReceiveResponse completionHandler (cancel) 3 didCompleteWithError 0x10ebf8840 - Created NetworkDataTaskBlob for blob:http://127.0.0.1:8000/dc810a1b-32ab-494a-a7c6-bdd08c15e3d9 0x10ebf8840 - NetworkDataTaskBlob::didReceiveResponse(0) 0x10ebf8840 - NetworkDataTaskBlob::didReceiveResponse completionHandler (1) 0x10ebf8840 - NetworkDataTaskBlob::download to /var/folders/d_/755k76r526315y2mt8ffpc3m0000gn/T/WebKitTestRunner-GrEfEg/foo.pdf 0x10ebf8840 - NetworkDataTaskBlob::didFailDownload
Alex Christensen
Comment 22 2016-11-01 16:06:08 PDT
I had to add #include "Logging.h" to NetworkDataTaskBlob.cpp to get it to compile on Sierra, btw
Alex Christensen
Comment 23 2016-11-01 16:55:39 PDT
errno is 1 #define EPERM 1 /* Operation not permitted */
Alex Christensen
Comment 24 2016-11-01 17:16:04 PDT
Aha! We're not using the SandboxExtension::Handle given to setPendingDownloadLocation
Alex Christensen
Comment 25 2016-11-01 17:21:53 PDT
Alex Christensen
Comment 26 2016-11-01 17:23:19 PDT
Added sandbox extension handling, r=me, please two more reviewers look at this because it touches the disk with openFile, etc.
Carlos Garcia Campos
Comment 27 2016-11-02 00:27:43 PDT
(In reply to comment #24) > Aha! We're not using the SandboxExtension::Handle given to > setPendingDownloadLocation Ah, right :-)
Carlos Garcia Campos
Comment 28 2016-11-02 00:28:38 PDT
(In reply to comment #15) > Comment on attachment 293337 [details] > Try to fix failing tests > > View in context: > https://bugs.webkit.org/attachment.cgi?id=293337&action=review > > I'm sure this is about 95% correct, but blobs and downloads don't work on > Sierra and I'm not sure what's wrong. Chris wrote our blob download code. > > > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:258 > > +void NetworkDataTaskBlob::didReceiveResponse(Error errorCode) > > Please add LOG(NetworkSession, ...) to each of these callbacks so they can > actually be debugged. > > > Source/WebKit2/NetworkProcess/NetworkSession.h:64 > > + HashSet<NetworkDataTask*> m_dataTaskSet; > > This is strange to have NetworkDataTaskBlobs kept in a set here on cocoa but > not with Network-NetworkDataTasks. That might be the right thing to do, but > I'm not sure. Actually, NetworkSessionCocoa::invalidateAndCancel() should call NetworkSession::invalidateAndCancel() to invalidate the blobs. I'll update the patch.
Carlos Garcia Campos
Comment 29 2016-11-02 02:59:06 PDT
Created attachment 293650 [details] Patch for landing
Carlos Garcia Campos
Comment 30 2016-11-02 09:37:27 PDT
Alex, I didn't ask for r? because you already said r=me and the patch already has the Reviewed by lines filled. So, other reviewers could just comment or even set cq+/-
Alex Christensen
Comment 31 2016-11-02 13:43:32 PDT
Comment on attachment 293650 [details] Patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=293650&action=review https://trac.webkit.org/changeset/208298 > Source/WebKit2/NetworkProcess/Downloads/Download.cpp:173 > String Download::decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite) We're trying to get rid of this in favor of the async version, but that can be done in a followup. > Source/WebKit2/NetworkProcess/NetworkDataTaskBlob.cpp:566 > + ASSERT(!m_sandboxExtension); I had to move this assertion to after the check for downloads.
Carlos Garcia Campos
Comment 32 2016-11-03 02:04:36 PDT
Comment on attachment 293650 [details] Patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=293650&action=review >> Source/WebKit2/NetworkProcess/Downloads/Download.cpp:173 >> String Download::decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite) > > We're trying to get rid of this in favor of the async version, but that can be done in a followup. This is still not used when NETWORK_SESSION is enabled, I just moved the ifdefs to include more things that are now only built when NETWORK_SESSION si disabled.
Alex Christensen
Comment 33 2016-11-03 14:11:21 PDT
Rolled out in http://trac.webkit.org/changeset/208344 This caused guardmalloc and asan crashes. Something about the change to NetworkLoad::continueWillSendRequest Tests like http/tests/xmlhttprequest/redirect-cross-origin-sync.html were crashing
Carlos Garcia Campos
Comment 34 2016-11-04 03:03:31 PDT
(In reply to comment #33) > Rolled out in http://trac.webkit.org/changeset/208344 > This caused guardmalloc and asan crashes. Something about the change to > NetworkLoad::continueWillSendRequest > Tests like http/tests/xmlhttprequest/redirect-cross-origin-sync.html were > crashing Yes, I screwed it up trying to make it easier to read. So, the thing is that when the new request is null we call didCompleteWithError, that notifies the NetworkResourceLoader that cleans it up deleting the network load. Before the patch we called the completion handler with { }, but with the patch we pass m_currentRequest because it was already null anyway, but at this point it has been freed. So, I'll bring back the previous approach duplicating the call to the complation handler to only use m_currentRequest when it's not null, and ensuring we return after didCompleteWithError because we will be freed at that point.
Carlos Garcia Campos
Comment 35 2016-11-04 03:06:02 PDT
Created attachment 293876 [details] Updated patch for landing
Alex Christensen
Comment 36 2016-11-04 11:11:30 PDT
Note You need to log in before you can comment on or make changes to this bug.