Closed
Bug 1380255
Opened 8 years ago
Closed 7 years ago
Make FetchDriver thread safe
Categories
(Core :: DOM: Core & HTML, defect, P2)
Tracking
()
RESOLVED
FIXED
mozilla58
Tracking | Status | |
---|---|---|
firefox-esr52 | --- | unaffected |
firefox54 | --- | unaffected |
firefox55 | --- | unaffected |
firefox56 | --- | unaffected |
firefox57 | --- | unaffected |
firefox58 | --- | fixed |
People
(Reporter: dragana, Assigned: bkelly)
References
Details
Attachments
(3 files, 2 obsolete files)
2.25 KB,
patch
|
baku
:
review+
|
Details | Diff | Splinter Review |
6.30 KB,
patch
|
bkelly
:
review+
|
Details | Diff | Splinter Review |
1.21 KB,
patch
|
kmag
:
review+
|
Details | Diff | Splinter Review |
FetchDrive implements nsIThreadRetargetableStreamListener and declares NS_DECL_ISUPPORTS.
It should be NS_DECL_THREADSAFE_ISUPPORTS if it wants to be retargetable.
Updated•8 years ago
|
Group: core-security → dom-core-security
Keywords: csectype-race,
sec-high
Reporter | ||
Updated•8 years ago
|
status-firefox54:
--- → unaffected
status-firefox55:
--- → unaffected
status-firefox56:
--- → affected
Reporter | ||
Comment 1•8 years ago
|
||
I found that nsWebRequestListener and nsStreamListenerWrapper have the same problem. I have open bugs for them too. I do not know if the problem is going to be triggered at all for them (it will not be triggered if one of the listeners in a chain vetoes retargeting), but anyway it should be fixed.
Assignee | ||
Comment 2•8 years ago
|
||
Why is this only a problem in FF56? Couldn't this have triggered in non-e10s in older releases?
Reporter | ||
Comment 3•8 years ago
|
||
(In reply to Ben Kelly [reviewing, but slowly][:bkelly] from comment #2)
> Why is this only a problem in FF56? Couldn't this have triggered in
> non-e10s in older releases?
I think it is connected with nsUknownDecoder somehow, which is retargetable only since 56. It was not triggered before 56 (or at least we do not know about it). Maybe I am wrong. Please change flags.
Assignee | ||
Comment 4•8 years ago
|
||
Ok, that makes sense.
Updated•8 years ago
|
status-firefox-esr52:
--- → unaffected
Reporter | ||
Comment 5•8 years ago
|
||
Ben, can you take this or do you know if there is someone who can take it?
Flags: needinfo?(bkelly)
Assignee | ||
Comment 6•8 years ago
|
||
Andrew, can you find someone to work this? I am just starting to dig out of PTO email.
Flags: needinfo?(bkelly) → needinfo?(overholt)
Summary: Make FetchDrive thread safe → Make FetchDriver thread safe
Comment 7•8 years ago
|
||
Sorry for the delay here. I think Catalin is probably best positioned to take this when he's back from PTO. He's got some other stuff he's trying to land but can probably parallelize and focus on this 100% when that's finished.
Flags: needinfo?(overholt) → needinfo?(catalin.badea392)
Reporter | ||
Comment 8•8 years ago
|
||
In bug 1379631, I have disabled OMT delivery for FetchDriver. Please turn it on again in this bug. That is also a work around for this bug on 56.
Reporter | ||
Comment 9•8 years ago
|
||
I am marking this unaffected for 56 as a work around landed in bug 1379631.
We can still uplift to 56 fix for this bug and turn on OMT if we want.
Updated•7 years ago
|
Assignee: nobody → catalin.badea392
Priority: -- → P2
Assignee | ||
Comment 10•7 years ago
|
||
Given comment 8, can we remove the privacy bit here? It doesn't seem like an active security problem.
Comment 11•7 years ago
|
||
Don't think there's anything else to be done, FetchDriver is already designed
to accept OnDataAvailable off the main thread.
Attachment #8912183 -
Flags: review?(amarchesini)
Updated•7 years ago
|
Attachment #8912183 -
Flags: review?(amarchesini) → review+
Updated•7 years ago
|
status-firefox57:
--- → unaffected
Flags: needinfo?(catalin.badea392)
Comment 12•7 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/22a322b57f5000dcd4a28b52d836a6dbec97eaa6
Is the bot sleeping?
Landed this without sec-approval because there was a fix landed in firefox 56 (comment #9) and esr is marked as unaffected.
Comment 13•7 years ago
|
||
(In reply to Cătălin Badea (:catalinb) from comment #12)
> Is the bot sleeping?
Pulsebot doesn't have access to sec bugs.
Comment 14•7 years ago
|
||
Backed out due to test failures: https://hg.mozilla.org/integration/mozilla-inbound/rev/999b0a7cc8dc
https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&revision=22a322b57f5000dcd4a28b52d836a6dbec97eaa6&filter-resultStatus=testfailed&filter-resultStatus=busted&filter-resultStatus=exception&filter-resultStatus=retry&filter-resultStatus=usercancel&filter-resultStatus=runnable
Assignee | ||
Comment 15•7 years ago
|
||
This shouldn't be a sec bug per comment 8.
Updated•7 years ago
|
Group: dom-core-security
Comment 16•7 years ago
|
||
(In reply to Cătălin Badea (:catalinb) from comment #14)
> Backed out due to test failures:
Are there plans to re-land this?
Flags: needinfo?(catalin.badea392)
Assignee | ||
Comment 17•7 years ago
|
||
Since Catalin is busy with child array list I'm going to steal this.
Assignee: catalin.badea392 → bkelly
Status: NEW → ASSIGNED
Flags: needinfo?(catalin.badea392)
Assignee | ||
Updated•7 years ago
|
Keywords: csectype-race,
sec-high
Assignee | ||
Comment 18•7 years ago
|
||
It seems that test_ext_webrequest_responseBody.html expects to attach the to the channel and receive OnDataAvailable() calls on the main thread. The test just happens to use fetch() here, as far as I can tell.
Kris, is there some mechanism that webrequest uses to disable channel retargeting for other code? Maybe we are missing something in fetch()? Or is this possibly broken for all webrequest uses where channels are retargeted to other threads?
Flags: needinfo?(kmaglione+bmo)
Comment 19•7 years ago
|
||
(In reply to Ben Kelly [:bkelly] from comment #18)
> It seems that test_ext_webrequest_responseBody.html expects to attach the to
> the channel and receive OnDataAvailable() calls on the main thread. The
> test just happens to use fetch() here, as far as I can tell.
>
> Kris, is there some mechanism that webrequest uses to disable channel
> retargeting for other code? Maybe we are missing something in fetch()? Or
> is this possibly broken for all webrequest uses where channels are
> retargeted to other threads?
It doesn't expect to receive those calls on the main thread. It generally prefers to receive data on the STS thread, but should work on any thread. The data always gets filtered through the main thread of the extension process, but the result always gets re-dispatched on whichever thread the last onDataAvailable call happens on.
Flags: needinfo?(kmaglione+bmo)
Assignee | ||
Comment 20•7 years ago
|
||
Hmm, it seems webrequest tries to support retargeting:
https://searchfox.org/mozilla-central/source/toolkit/components/extensions/webrequest/StreamFilterParent.cpp#120
https://searchfox.org/mozilla-central/source/toolkit/components/extensions/webrequest/ChannelWrapper.cpp#946
And in e10s mode it seems the StreamFilter IPC should execute on the main thread there.
Maybe this is more of a race between the stream filter and the fetch() response.text() resolving.
I'll debug tomorrow. Sorry for the flag spam.
Assignee | ||
Comment 21•7 years ago
|
||
Actually, it looks like fetch() lost some data in there:
fetch() produced:
```
<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title></title>\n </head>\n <body>\nconsectetur adipiscing elit, <br>\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br>\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <br>\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <br>\nExcepteur sint occaecat cupidatat non proident, <br>\nsunt in culpa qui officia deserunt mollit anim id est laborum.<br>\n\n </body>\n </html>\n
```
webrequest saw:
```
<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title></title>\n </head>\n <body>\nLorem ipsum dolor sit amet, <br>\nconsectetur adipiscing elit, <br>\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br>\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <br>\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <br>\nExcepteur sint occaecat cupidatat non proident, <br>\nsunt in culpa qui officia deserunt mollit anim id est laborum.<br>\n\n </body>\n </html>\n
```
Comment 22•7 years ago
|
||
(In reply to Ben Kelly [:bkelly] from comment #21)
> Actually, it looks like fetch() lost some data in there:
Yeah, there's a bug for that that's on my todo list for this week. When data delivery is targetted to a thread pool other than the one that owns the StreamFilter worker, the data chunks sometimes wind up being processed out of order. I need to figure out a safe locking arrangement that avoids that problem.
Assignee | ||
Comment 23•7 years ago
|
||
Hmm, looking at a debug build, though, shows that StreamFilterParent hit an assertion:
https://treeherder.mozilla.org/logviewer.html#?job_id=133326989&repo=mozilla-inbound&lineNumber=39676
Kris, sorry to bother you again, but does that make any sense to you? Shouldn't fetch() be in the client side here?
If this is a known issue in StreamFilter, should we perhaps mark it not safe for ThreadRetargeting?
Assignee | ||
Comment 24•7 years ago
|
||
Or is there another solution so I can land this fetch() change if this is a known issue in webrequest?
Comment 25•7 years ago
|
||
(In reply to Ben Kelly [:bkelly] from comment #23)
> Shouldn't fetch() be in the client side here?
No, that arrangement here is kind of unusual. The parent side is always in the
process that the request originated in (i.e., the process that owns the
HttpChannelChild), and the child side is always in the extension process.
The parent side used to always be in the parent process, but for complicated
reasons related to content decoders, it's really difficult to correctly filter
response data from the parent process.
> If this is a known issue in StreamFilter, should we perhaps mark it not safe
> for ThreadRetargeting?
We could, but I'd rather just fix it correctly. Like I said, it's on my todo
list for this week.
Assignee | ||
Comment 26•7 years ago
|
||
(In reply to Kris Maglione [:kmag] (long backlog; ping on IRC if you're blocked) from comment #25)
> We could, but I'd rather just fix it correctly. Like I said, it's on my todo
> list for this week.
Ok, can you make that bug block this one?
Assignee | ||
Comment 27•7 years ago
|
||
Andrea, this patch makes us only trigger the FetchDriverObserver::OnDataAvailable() callback if its actually needed to update a FetchObserver. In addition, we only call it on the first ODA.
The goal is to remove as many main thread runnables as possible while receiving data. Unfortunately the OnDataAvailable() code was sending an additional MT runnable for every ODA which kind of defeated the point of retargeting OMT.
Attachment #8917842 -
Flags: review?(amarchesini)
Comment 28•7 years ago
|
||
Comment on attachment 8917842 [details] [diff] [review]
P2 Don't fire FetchDriverObserver::OnDataAvailable() for every FetchDriver ODA callback. r=baku
Review of attachment 8917842 [details] [diff] [review]:
-----------------------------------------------------------------
::: dom/fetch/Fetch.cpp
@@ +508,5 @@
> +bool
> +MainThreadFetchResolver::NeedOnDataAvailable()
> +{
> + NS_ASSERT_OWNINGTHREAD(MainThreadFetchResolver);
> + return mFetchObserver;
return !!mFetchObserver;
just to make it clear that we are returning a boolean.
@@ +715,5 @@
> +WorkerFetchResolver::NeedOnDataAvailable()
> +{
> + AssertIsOnMainThread();
> + MutexAutoLock lock(mPromiseProxy->Lock());
> + return mFetchObserver;
here as well.
Attachment #8917842 -
Flags: review?(amarchesini) → review+
Assignee | ||
Comment 29•7 years ago
|
||
Assignee | ||
Comment 30•7 years ago
|
||
Attachment #8917842 -
Attachment is obsolete: true
Attachment #8917864 -
Flags: review+
Assignee | ||
Comment 31•7 years ago
|
||
Hmm, the try run is suggesting that maybe the webrequest test is not failing any more with fetch() OMT retargetting.
Assignee | ||
Comment 32•7 years ago
|
||
Oh, re-triggers show its clear still a problem.
Assignee | ||
Comment 33•7 years ago
|
||
Assignee | ||
Comment 34•7 years ago
|
||
Comment on attachment 8917940 [details] [diff] [review]
P3 Disable OMT retargeting of fetch() requests while being traced until webrequest can be fixed. r=kmag
Kris, I understand you have this problem on your todo list, but I'd like to avoid letting this bug sit for any longer. I'd like to land OMT delivery now while you continue to work on the webrequest issue.
To that end, what do you think about this? It adds a way to detect if channel tracing is being used and avoids thread retargeting in that case.
This of course disables retargeting when devtools network monitor is active as well, but that should be ok for the near term. In the long run we will remove this restriction.
https://treeherder.mozilla.org/#/jobs?repo=try&revision=74154c8fce2bcdd537e3054af6612c2aabc48acb
Attachment #8917940 -
Flags: review?(kmaglione+bmo)
Assignee | ||
Comment 35•7 years ago
|
||
Try is green with P3. I did 10 retriggers and could not reproduce the previous failure.
Comment 36•7 years ago
|
||
Comment on attachment 8917940 [details] [diff] [review]
P3 Disable OMT retargeting of fetch() requests while being traced until webrequest can be fixed. r=kmag
Review of attachment 8917940 [details] [diff] [review]:
-----------------------------------------------------------------
If we're going to do this, let's just return failure in StreamFilterParent::CheckListenerChain()
Attachment #8917940 -
Flags: review?(kmaglione+bmo) → review-
Assignee | ||
Comment 37•7 years ago
|
||
Ok. That does seem best given other consumers try to retarget channels as well. Sorry to push for this right now, but it should be easily reversed once the problem is solved. Thanks.
https://treeherder.mozilla.org/#/jobs?repo=try&revision=ce8a3391a351bd64f5abe196aa822622314396f5
Attachment #8918057 -
Flags: review?(kmaglione+bmo)
Assignee | ||
Updated•7 years ago
|
Attachment #8917940 -
Attachment is obsolete: true
Updated•7 years ago
|
Attachment #8918057 -
Flags: review?(kmaglione+bmo) → review+
Comment 38•7 years ago
|
||
Pushed by bkelly@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/0db1445c1db9
FetchDriver should have threadsafe refcounting. r=baku
https://hg.mozilla.org/integration/mozilla-inbound/rev/839e4b1245ca
P2 Don't fire FetchDriverObserver::OnDataAvailable() for every FetchDriver ODA callback. r=baku
https://hg.mozilla.org/integration/mozilla-inbound/rev/213cba8335fd
P3 Disable channel thread retargeting when webrequest is tracing the channel. r=kmag
![]() |
||
Comment 39•7 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/0db1445c1db9
https://hg.mozilla.org/mozilla-central/rev/839e4b1245ca
https://hg.mozilla.org/mozilla-central/rev/213cba8335fd
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
status-firefox58:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•