Bug 158463 - Network: Correctly report encoded data length (transfer size) from CFNetwork to NetworkResourceLoader
Summary: Network: Correctly report encoded data length (transfer size) from CFNetwork ...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-06 22:42 PDT by Alex Christensen
Modified: 2021-09-10 09:04 PDT (History)
15 users (show)

See Also:


Attachments
Patch (10.20 KB, patch)
2016-06-06 22:49 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (10.22 KB, patch)
2016-06-07 09:51 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (48.38 KB, patch)
2016-06-07 18:14 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (51.03 KB, patch)
2016-06-07 22:11 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (52.47 KB, patch)
2016-06-07 23:06 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (58.74 KB, patch)
2016-06-08 00:08 PDT, Alex Christensen
achristensen: review-
Details | Formatted Diff | Diff
[PATCH] Work in Progress (53.42 KB, patch)
2017-07-03 18:55 PDT, Joseph Pecoraro
joepeck: 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 2016-06-06 22:42:50 PDT
Correctly report encoded data length from CFNetwork to NetworkResourceLoader
Comment 1 Alex Christensen 2016-06-06 22:49:15 PDT
Created attachment 280676 [details]
Patch
Comment 2 Alex Christensen 2016-06-07 09:51:22 PDT
Created attachment 280715 [details]
Patch
Comment 3 Darin Adler 2016-06-07 15:17:13 PDT
Comment on attachment 280715 [details]
Patch

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

> Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:263
> +        m_handle->client()->didReceiveBuffer(m_handle, SharedBuffer::wrapNSData(data), static_cast<int>(lengthReceived));

This chops a 64-bit integer and turns it into a 32-bit integer. Why is that OK?

> Source/WebKit2/NetworkProcess/NetworkLoad.cpp:252
> +void NetworkLoad::didReceiveData(RefPtr<SharedBuffer>&& buffer, int64_t encodedDataLength)

How did you choose the type int64_t? Why signed rather than unsigned? Also, other places in the code use “[unsigned] long long” for this.

> Source/WebKit2/NetworkProcess/NetworkLoad.cpp:255
> +    m_client.didReceiveBuffer(WTFMove(buffer), static_cast<int>(encodedDataLength));

This chops a 64-bit integer and turns it into a 32-bit integer. Why is that OK?
Comment 4 Alex Christensen 2016-06-07 15:38:47 PDT
(In reply to comment #3)
> Comment on attachment 280715 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=280715&action=review
> 
> > Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:263
> > +        m_handle->client()->didReceiveBuffer(m_handle, SharedBuffer::wrapNSData(data), static_cast<int>(lengthReceived));
> 
> This chops a 64-bit integer and turns it into a 32-bit integer. Why is that
> OK?
There is great inconsistency in how this is passed around.  It should be fixed.
> 
> > Source/WebKit2/NetworkProcess/NetworkLoad.cpp:252
> > +void NetworkLoad::didReceiveData(RefPtr<SharedBuffer>&& buffer, int64_t encodedDataLength)
> 
> How did you choose the type int64_t? Why signed rather than unsigned? Also,
> other places in the code use “[unsigned] long long” for this.
That's what is used in NSURLSession.h.
@property (readonly) int64_t countOfBytesReceived;
There's a comment saying it can be 0 or -1.
Comment 5 Alex Christensen 2016-06-07 16:14:09 PDT
rdar://problem/21319035
Comment 6 Alex Christensen 2016-06-07 18:14:52 PDT
Created attachment 280756 [details]
Patch
Comment 7 Alex Christensen 2016-06-07 22:11:08 PDT
Created attachment 280769 [details]
Patch
Comment 8 Alex Christensen 2016-06-07 23:06:41 PDT
Created attachment 280774 [details]
Patch
Comment 9 Alex Christensen 2016-06-08 00:08:39 PDT
Created attachment 280784 [details]
Patch
Comment 10 Alex Christensen 2016-06-08 11:47:26 PDT
Comment on attachment 280784 [details]
Patch

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

> Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm:265
> +        networkDataTask->didReceiveData(WebCore::SharedBuffer::wrapNSData(data), [dataTask countOfBytesReceived]);

[dataTask countOfBytesReceived] returns the decoded size, not the encoded size.  That's exactly the same as the sum of the previous data->size()s.  This gives us no additional information.
Comment 11 Darin Adler 2016-06-09 20:00:43 PDT
Comment on attachment 280715 [details]
Patch

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

>>> Source/WebKit2/NetworkProcess/NetworkLoad.cpp:252
>>> +void NetworkLoad::didReceiveData(RefPtr<SharedBuffer>&& buffer, int64_t encodedDataLength)
>> 
>> How did you choose the type int64_t? Why signed rather than unsigned? Also, other places in the code use “[unsigned] long long” for this.
> 
> That's what is used in NSURLSession.h.
> @property (readonly) int64_t countOfBytesReceived;
> There's a comment saying it can be 0 or -1.

OK, but for future reference, that doesn’t make it the correct type for platform-independent code.
Comment 12 Joseph Pecoraro 2017-04-12 18:38:31 PDT
<rdar://problem/27927293>
Comment 13 Joseph Pecoraro 2017-07-03 11:11:23 PDT
> Comment on attachment 280784 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=280784&action=review
> 
> > Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm:265
> > +        networkDataTask->didReceiveData(WebCore::SharedBuffer::wrapNSData(data), [dataTask countOfBytesReceived]);
> 
> [dataTask countOfBytesReceived] returns the decoded size, not the encoded
> size.  That's exactly the same as the sum of the previous data->size()s. 
> This gives us no additional information.

There is a new SPI we should be able to use now to get the encoded size:
-[NSURLSessionTask _countOfBytesReceivedEncoded]

I'll update the patch.
Comment 14 Joseph Pecoraro 2017-07-03 13:10:52 PDT
Comment on attachment 280784 [details]
Patch

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

> Source/WebKit/WebCoreSupport/WebResourceLoadScheduler.cpp:94
>  WebResourceLoadScheduler::~WebResourceLoadScheduler()
>  {
> +    // FIXME: Why isn't m_nonHTTPProtocolHost deleted?
>  }

It looks like this should delete the host, but I think the WebResourceLoadScheduler (owned by the PlatformStrategy) is never be destroyed. This could move to a separate issue.
Comment 15 Joseph Pecoraro 2017-07-03 18:55:02 PDT
Created attachment 314544 [details]
[PATCH] Work in Progress

I don't think the new SPI is enough. But I'm attaching my work in progress so it doesn't get lost.
Comment 16 Joseph Pecoraro 2017-07-03 18:56:40 PDT
Comment on attachment 314544 [details]
[PATCH] Work in Progress

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

> Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm:405
> +        if ([dataTask respondsToSelector:@selector(_countOfBytesReceivedEncoded)]) {
> +            WTFLogAlways(">>> didReceiveData (%u) (%u)", (unsigned)dataTask._countOfBytesReceivedEncoded, (unsigned)dataTask.countOfBytesReceived);
> +            bytesReceived = dataTask._countOfBytesReceivedEncoded ?: dataTask.countOfBytesReceived;
> +        }

This is not good enough.

  1. If the response is encoded (compressed) data, then _countOfBytesReceivedEncoded starts with zero and doesn't include headers...
  2. If the response is uncompressed data, then countOfBytesReceived starts with non-zero and includes the header size.

So without knowing if we are receiving compressed / uncompressed data we can't know which set of APIs to use.