Closed
Bug 1134609
Opened 8 years ago
Closed 8 years ago
make Fetch Request constructor less destructive to input on error
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla43
Tracking | Status | |
---|---|---|
firefox43 | --- | fixed |
People
(Reporter: bkelly, Assigned: A-deLuna, Mentored)
References
Details
(Whiteboard: [good first bug][lang=c++])
Attachments
(1 file, 2 obsolete files)
6.08 KB,
patch
|
bkelly
:
review+
|
Details | Diff | Splinter Review |
The Fetch spec has been updated to make the Request constructor less destructive to the input when an error is hit: https://github.com/slightlyoff/ServiceWorker/issues/629
Comment 1•8 years ago
|
||
Relevant code is the Request constructor in dom/fetch/Request.cpp.
Mentor: bkelly
Comment 2•8 years ago
|
||
I would like to work on this . Please assign it to me .
Reporter | ||
Updated•8 years ago
|
Assignee: nobody → technozoom88
Status: NEW → ASSIGNED
Comment 3•8 years ago
|
||
Could you please elaborate more on the problem ? Does it mean that the constructor should not destroy a passed in object if the constructor algorithm results in an error?
Reporter | ||
Comment 4•8 years ago
|
||
Right. Previously, the Request constructor set the body used flag on the input immediately. This effectively consumed the input Request even if the constructor threw an error. The new spec text is careful not to set the body used flag until success is guaranteed. The text can be found here: https://fetch.spec.whatwg.org/#dom-request See the logic around `temporaryBody` and setting the input body used flag, etc. Compare that to the code in dom/fetch/Request.cpp's Constructor() method.
Assignee | ||
Comment 5•8 years ago
|
||
Hello Ben, I've tried to implement the spec, feedback is appreciated. Also there are some outdated comments that point a different step number than the current spec, should that be fixed as a separate bug or should I include it in this one?
Attachment #8635213 -
Flags: review?(bkelly)
Reporter | ||
Updated•8 years ago
|
Assignee: technozoom88 → tonydelun
Reporter | ||
Comment 6•8 years ago
|
||
Comment on attachment 8635213 [details] [diff] [review] bug-1134609-RequestConstructorLessDestructive Review of attachment 8635213 [details] [diff] [review]: ----------------------------------------------------------------- This looks pretty good to me. Can you add a test, though? I think something along the lines of: var r1 = new Request('http://example.com', { method: 'POST', body: 'hello world' }); try { var r2 = new Request(r1, { method: 'GET' }); } catch() { // should throw } ok(!r1.bodyUsed, 'initial request should not be consumed by failed Request constructor'); ::: dom/fetch/Request.cpp @@ +137,2 @@ > nsRefPtr<InternalRequest> request; > bool inputRequestHasBody = false; I think you can remove inputRequestHasBody now. @@ +325,5 @@ > requestHeaders->Append(NS_LITERAL_CSTRING("Content-Type"), > contentType, aRv); > } > > if (aRv.Failed()) { While you're here, can you add an NS_WARN_IF() to this Failed() check?
Attachment #8635213 -
Flags: review?(bkelly)
Assignee | ||
Comment 7•8 years ago
|
||
Added test case, there are several other aRv.Failed() checks without NS_WARN_IF() in the constructor, should I also change them in this patch?
Attachment #8635213 -
Attachment is obsolete: true
Attachment #8645879 -
Flags: review?(bkelly)
Reporter | ||
Comment 8•8 years ago
|
||
Comment on attachment 8645879 [details] [diff] [review] bug-1134609-RequestConstructorLessDestructive Review of attachment 8645879 [details] [diff] [review]: ----------------------------------------------------------------- Thanks! r=me We don't need to change the other failure checks to warn right now. Lets just do the one we're touching.
Attachment #8645879 -
Flags: review?(bkelly) → review+
Assignee | ||
Comment 9•8 years ago
|
||
I'm trying to push to Try, but I'm getting this error, what could be the cause?
>>pushing to ssh://hg.mozilla.org/try
>>no revisions specified to push; using . to avoid pushing multiple heads
>>searching for changes
>>remote: abort: could not lock working directory of /repo/hg/mozilla/try: Permission denied
>>abort: stream ended unexpectedly (got 0 bytes, expected 4)
patch message is "try: -b do -p all -u all[x64] -t none"
Reporter | ||
Comment 10•8 years ago
|
||
Do you have your ssh key enabled for hg? I use ssh-agent and ssh-add to do this. Also, what command are you using to do the push? hg push -f ssh://hg.mozilla.org/try?
Assignee | ||
Comment 11•8 years ago
|
||
It's all fixed now, there was a problem with my account permissions. try build: https://treeherder.mozilla.org/#/jobs?repo=try&revision=f81f0a8676e9
Assignee | ||
Comment 12•8 years ago
|
||
I'm running into trouble when implementing this part of the spec: >>35. If input is a Request object and input's body is non-null, run these substeps: >> 1. Set input's body to null. >> 2. Set input's used flag. But InternalRequest has an assertion that prevents us from doing this. https://dxr.mozilla.org/mozilla-central/source/dom/fetch/InternalRequest.h#322 What should be done in this case?
Flags: needinfo?(bkelly)
Reporter | ||
Comment 13•8 years ago
|
||
Looking at the steps here: https://fetch.spec.whatwg.org/#dom-request I don't think InternalRequest::GetRequestConstructorCopy should be copying the body. I don't see it in: "Set request to a new request whose url is request's current url, method is request's method, header list is a copy of request's header list, unsafe-request flag is set, client is entry settings object, window is window, origin is origin, force-Origin-header flag is set, same-origin data-URL flag is set, referrer is request's referrer, referrer policy is request's referrer policy, destination is the empty string, mode is request's mode, credentials mode is request's credentials mode, cache mode is request's cache mode, redirect mode is request's redirect mode, and integrity metadata is request's integrity metadata." With your changes it seems the body will get set on the new request via your temporaryBody variable after the copy is made. So I *think* you can remove this line: https://dxr.mozilla.org/mozilla-central/source/dom/fetch/InternalRequest.cpp#32 I would recommend replacing it with a comment that the body is handled separately by the Request::Constructor algorithm. Then you just need to deal with the SetBody(nullptr) case. I think you can address that by changing the SetBody() assert to MOZ_ASSERT_IF(aStream, !mBodyStream).
Flags: needinfo?(bkelly)
Assignee | ||
Comment 14•8 years ago
|
||
Added change to InternalRequest::SetBody() assertion. Tried to remove the line you suggested: https://dxr.mozilla.org/mozilla-central/source/dom/fetch/InternalRequest.cpp#32 But when running dom/tests/mochitest/fetch/test_fetch_basic_http.html I get the following error: >>39 INFO SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data >>40 INFO JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Attachment #8645879 -
Attachment is obsolete: true
Attachment #8649020 -
Flags: review?(bkelly)
Assignee | ||
Comment 15•8 years ago
|
||
try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=05bf9186b17b
Reporter | ||
Comment 16•8 years ago
|
||
Comment on attachment 8649020 [details] [diff] [review] bug-1134609-RequestConstructorLessDestructive Review of attachment 8649020 [details] [diff] [review]: ----------------------------------------------------------------- Well, if all the tests pass without removing that line, LGTM! Can you update your tree and do another try, though, to see whats up with those leaks? They seem unrelated, but lets verify. Thanks.
Attachment #8649020 -
Flags: review?(bkelly) → review+
Assignee | ||
Comment 17•8 years ago
|
||
All right all tests passed, I'll mark for checkin needed. Thanks again Ben! try build: https://treeherder.mozilla.org/#/jobs?repo=try&revision=91367ecb5799
Keywords: checkin-needed
Comment 18•8 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/8e4ca69ff980
Keywords: checkin-needed
Comment 20•8 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/8e4ca69ff980
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
status-firefox43:
--- → fixed
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
Updated•4 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•