Repository navigation
devtools: limit size of response bodies sent to the network tab - #48909
Conversation
|
I'm happy to review this, though it might be a few days before I have the time |
Take you time :) |
|
So I am going to keep this discussion here. I think we should combine these changes with the general resource exhaustion. |
|
Did you see #48894 ? Are you suggesting that we should have an overall size limit in fetch, resulting in a network error? I think we should definitely have some kind of limit. For instance, we likely shouldn't have very large entries in the cache. But a blanket limit would mean that we wouldn't be able to download very large files, which goes through fetch as well. SRI complicates the picture as well, as we'd need the full body before processing it I think. It's worth looking at what other browsers do. I still think the special treatment for Devtools is appropriate here, though I haven't read the PR yet. |
|
I'm struggling to manually test this PR. There seems to be a preexisting issue where the response body in devtools is empty, at in some cases. Did you manually test that responses are truncated? If so, how? |
Yes I did. I think the way I did it was, I created a temporary file that was larger than the recommended size to be truncated (1MB I think)- it contains numbers from 1 to 255. I ran the file through Servo and open Firefox devtools network tab where I check the response tab. The fix worked and only 1 to 133? came in response - meaning the truncation worked. |
|
It's been days since I worked on it and I've had to work on several other issues, so I can't remember everything exactly, as I also stepped away from my PC |
freyacodes
left a comment
There was a problem hiding this comment.
Yesterday I tried doing something alike to what you did, though I wasn't getting the body at all. I could see that I was getting scripts and SVGs on webpages, and I realised that I could test it using a small limit (e.g. 10 bytes)
./mach run --devtools 6080 --pref devtools_network_response_body_limit=10`
However, it's clear that servo doesn't seem to expose the flag that tells Firefox that a response is truncated. The point of tracking whether a response is truncated is to be able to alert the user. I realise that this might not have been too clear from the issue description. Truncated responses should look something like this:
I don't know how Firefox expects to find the truncation flag, that might require a bit of RE or reading the source. Ideally the flag would be checked by a Python devtools test, though this might be tricky with how glitchy the network tab is about showing response bodies currently.
| return; | ||
| } | ||
| let remaining = (limit as usize) | ||
| .saturating_add(1) |
There was a problem hiding this comment.
I'm sorry, I don't know how i missed this.
I'm not sure I remember exactly why I added it, I think it's added during debugging to increase the limit size by 1 byte.
I'm going to remove it now.
| request, | ||
| context, | ||
| response, | ||
| Some(capped_body_for_devtools(vec)), |
There was a problem hiding this comment.
I'm not familiar with send_response_to_devtools, but at first glance it appears to not communicate whether a response is truncated
| body: Option<Vec<u8>>, | ||
| body_truncated: bool, |
There was a problem hiding this comment.
body_truncated is meaningless if body is None. I think it would be fitting to merge body and body_truncated into one Option<T> where T is a struct representing both. Both here and elsewhere.
Thank you for this, was really helpful. I've been able to implement & manually test the truncation properly. Remains the communication of the truncation flag.
Maybe I'll push what I have while I work on that. |
ba5fbb3 to
0f54060
Compare
0f54060 to
265eeaa
Compare
|
As the banner refused to render despite servo truncating properly, I had to look into how firefox handles it so I can reverse-engineer the method. I found how the banner is triggered here which led to discovering this and here's how it's been watched I realised my previous approach was flawed, so I addressed both the tracking of the truncation state in net and the protocol serialization in devtools and created DevtoolsBodyBuffer. All tests still pass, checks are clean, and banner is being rendered in the network response tab. |
|
To manually test: I created a large file (2MB) like so; Then ran the servo build like so; |
| // When the body was truncated, report the true content size from the | ||
| // Content-Length header (i.e., the full original size) so that Firefox's | ||
| // ResponsePanel can compare `content.size >= limit` and display the | ||
| // "Response has been truncated" message, exactly as Firefox does. |
There was a problem hiding this comment.
| // "Response has been truncated" message, exactly as Firefox does. | |
| // "Response has been truncated" message |
This is a confusing comment because it is still Firefox making that decision
There was a problem hiding this comment.
I thought about that too, but I wasn't sure, I thought we're just borrowing Firefox's devtools to render ours.
Still a lot to understand here, thank you.
There was a problem hiding this comment.
I see. To elaborate: The Firefox desktop browser ships devtools as a client and a server. These are usually used together in the same application. However, the desktop version can also be used to connect to other running instances of Firefox as a client, such as to the android version, over the network. We take advantage of their preexisting client to communicate with our client, which is the piece of code that we are working with. This saves us from needing to develop and maintain a client of our own.
There was a problem hiding this comment.
Ohhk, so in simple terms, we can compare them to like a working space with its monitor and CPU separate but can work together when connected.
Now we (Servo) are borrowing their monitor to connect with our CPU...
Will Servo eventually have its own, or we can keep using it in production?
There was a problem hiding this comment.
It's say it's more akin to a debugger and a program.
A client of our own is likely out of scope for Servo, and wouldn't be part of the engine either way. I don't know what you mean by production, but keep in mind that devtools is off by default even if the compile flag is on.
There was a problem hiding this comment.
Thank you, I understand the relationship between them now.
What I meant by production is; when it becomes available for the public to use, just like Firefox and Chrome. Is Servo going to still incorporate Firefox's devtools?
I'm sorry my questions are getting too much, I'm just curious.
There was a problem hiding this comment.
Whether to include the devtools server (which mimics Firefox without being Firefox) is ultimately the choice of whomever decides to depend on Servo. We offer that choice by way of the devtools feature flag.
Either way I think we have strayed off-topic from this PR. Feel free to text me on Zulip if you have more general questions. We also have a dedicated devtools channel. Questions directly related to this PR are of course still welcome.
There was a problem hiding this comment.
Right, thank you.
| // When the body was truncated, report the true content size from the | ||
| // Content-Length header (i.e., the full original size) so that Firefox's | ||
| // ResponsePanel can compare `content.size >= limit` and display the |
There was a problem hiding this comment.
"true content size" and "full original size" are ambiguous and I am not sure what you mean by these
| let transferred_size = headers | ||
| .and_then(|header| header.typed_get::<ContentLength>()) | ||
| .map(|content_length_header| content_length_header.0); |
There was a problem hiding this comment.
This is not a correct way of representing the transmitted bytes. The content-length header is not always present or accurate. You could either:
- Get it from
net, which might not be trivial - Accept this as a limitation and file a new issue
There was a problem hiding this comment.
Thank you, I just realised firefox doesn't even need it for truncation.
I think I was just trying different methods when I couldn't get it to render the banner few days ago.
| transferred_size | ||
| .map(|s| s as usize) | ||
| .unwrap_or(body.data.len()) |
There was a problem hiding this comment.
This seems to be mixing up compressed and uncompressed sizes. I would think that this is supposed to be uncompressed size.
| #[cfg(feature = "devtools")] | ||
| let devtools_response_body = | ||
| devtools_body.map(DevtoolsBodyBuffer::into_response_body); | ||
| #[cfg(not(feature = "devtools"))] | ||
| let devtools_response_body = None; | ||
| send_response_to_devtools(request, context, response, devtools_response_body); |
There was a problem hiding this comment.
| #[cfg(feature = "devtools")] | |
| let devtools_response_body = | |
| devtools_body.map(DevtoolsBodyBuffer::into_response_body); | |
| #[cfg(not(feature = "devtools"))] | |
| let devtools_response_body = None; | |
| send_response_to_devtools(request, context, response, devtools_response_body); | |
| #[cfg(feature = "devtools")] | |
| let devtools_response_body = | |
| devtools_body.map(DevtoolsBodyBuffer::into_response_body); | |
| #[cfg(feature = "devtools")] | |
| send_response_to_devtools(request, context, response, devtools_response_body); |
265eeaa to
06b8333
Compare
|
Hi @freyacodes It's been a while, trust you're doing okay. |
|
Hi @freyacodes I looked into Firefox's NetworkResponseListener.sys.mjs here: and confirmed: decodedBodySize is the full uncompressed body size and that size is an alias set directly to decodedBodySize. In our implementation, DevtoolsBodyBuffer now accumulates the total uncompressed incoming chunk size across content_size, even when data past the truncation limit is discarded. We now pass this total count to decoded_body_size and size. All 393 tests still pass and the uncompressed size is now shown in the devtools:
|
freyacodes
left a comment
There was a problem hiding this comment.
Excellent work, I think this is ready to merge! I will try to get the attention of a maintainer
|
🔨 Triggering try run (#42923474647) for Linux (Devtools Tests) |
|
✨ Try run (#42923474647) succeeded. |
eerii
left a comment
There was a problem hiding this comment.
This looks great. Thank you so much @freyacodes for reviewing, and nice work @sabbCodes :)
Signed-off-by: Sabb <[email protected]>
a3ef98b to
75bac6c
Compare
|
Hi @eerii I've addressed the failed test that got this removed from merge queue. |
|
Looks like that's not related to this changes, could someone please re add this to the merge queue? |





Limited size of response bodies sent to the network tab similar to how firefox handles it as suggested
Testing:
./mach test-unit -p servo-netand./mach test-unit -p servo-net -- test_devtools_response_body_truncatedwere cleanFixes: #48891