MessageChannel can't work with TaskQueue
Categories
(Core :: IPC, enhancement)
Tracking
()
Tracking | Status | |
---|---|---|
firefox80 | --- | fixed |
People
(Reporter: jya, Assigned: jya)
References
(Blocks 2 open bugs, Regression)
Details
(Keywords: regression)
Attachments
(3 files, 3 obsolete files)
MessageChannel::Open takes an nsIEventTarget ;
When opening, it dispatches a task on this nsIEventTarget that calls MessageChannel::OnOpenAsSlave [1]
When OnOpenAsSlave runs, it stores the actual PRThread the task is running on [2]. And then in various places will assert that the current worker thread is the same as the actual thread it's running on [3].
When using a ThreadPool or a TaskQueue, you're never guaranteed that the actual thread the code is running on will always be the same.
So at present, while MessageChannel takes a nsIEventTarget as constructor, this nsIEventTarget can only ever be a nsThread.
[1] https://searchfox.org/mozilla-central/source/ipc/glue/MessageChannel.cpp#874
[2] https://searchfox.org/mozilla-central/source/ipc/glue/MessageChannel.cpp#904
[3] https://searchfox.org/mozilla-central/source/ipc/glue/MessageChannel.h#550
Comment 1•4 years ago
|
||
The severity field is not set for this bug.
:jld, could you have a look please?
For more information, please visit auto_nag documentation.
Comment 2•4 years ago
|
||
MessageChannel
(and IPDL in general) inherently needs a serial event target, so it will never work with ThreadPool
. But in principle it (and the associated checks that things are happening on the correct thread) could be generalized to work with abstract threads, like TaskQueue
.
Assignee | ||
Comment 3•4 years ago
|
||
(In reply to Jed Davis [:jld] ⟨⏰|UTC-6⟩ ⟦he/him⟧ from comment #2)
MessageChannel
(and IPDL in general) inherently needs a serial event target, so it will never work withThreadPool
. But in principle it (and the associated checks that things are happening on the correct thread) could be generalized to work with abstract threads, likeTaskQueue
.
TaskQueue is a nsISerialEventTarget object.
The main issue is what MessageChannel is doing to ensure you're on the right thread; It simply compares pointers of the PR_Thread which is the obviously wrong thing to do.
It could store the original nsISerialEventTarget is use is IsOnThread() method instead.
This would make it work with TaskQueue.
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 4•4 years ago
|
||
(In reply to Jed Davis [:jld] ⟨⏰|UTC-6⟩ ⟦he/him⟧ from comment #2)
MessageChannel
(and IPDL in general) inherently needs a serial event target, so it will never work withThreadPool
. But in principle it (and the associated checks that things are happening on the correct thread) could be generalized to work with abstract threads, likeTaskQueue
.
I should have provided more details about the bug originally mentioning ThreadPool.
This is the only implementation we have that is a nsIEventTarget and not a nsISerialEventTarget ;
The prototyping of IToplevelProtocol methods are to use nsIEventTarget ; which is nonsensical really as it must be a nsISerialEventTarget.
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 5•4 years ago
|
||
And the less use of MessageLoop, the better.
Assignee | ||
Comment 6•4 years ago
|
||
We now pass the target nsISerialEventTarget all the way down to MessageChannel::CommonThreadOpenInit so that we don't have to rely on GetCurrentSerialEventTarget() to return the proper object (see bug 1637500).
Even when bug 1637500 will be fully fixed, it avoids any ambiguities as to what target thread we want to use.
Depends on D80654
Assignee | ||
Comment 7•4 years ago
|
||
We no longer rely of having a message loop for the worker thread.
Updated•4 years ago
|
Assignee | ||
Comment 8•4 years ago
|
||
NS_INLINE_DECL_REFCOUNTING macro doesn't properly work when the object is used on a thread that isn't backed by a single PRThread (such as TaskQueue). See bug 1648031.
The resolution of this issue is rather complex, and outside the scope of this series of change.
So for now, we create a new macro NS_INLINE_DECL_REFCOUNTING_ONEVENTTHREAD which will use a different mechanism to ensure the thread-safe usage of a class.
Assignee | ||
Comment 9•4 years ago
|
||
There's a small race that can happen when the remote decoder gets shutdown during xpcom shutdown; that would cause GetCurrentSerialEventTarget to return null. Leading to an assertion failure in ActorLifecycleProxy thread-safety check when PRemoteDecoderManagerParent gets destroyed.
So we use a background taskqueue instead and cleanup a bit the threading code in there allowed thanks to the TaskQueue ability to not require an explicit shutdown.
Assignee | ||
Comment 10•4 years ago
|
||
The STS dispatched the first event before setting mThread member. It was possible that the STS::Run() task got started before mThread was set and causing one of the nsISerialEventTarget methods to read mThread/mInitialised/mShuttingDown value as null or zero and they would have returned an error.
We rewrite the access to mThread to be lockless.
Comment 11•4 years ago
|
||
Comment on attachment 9159699 [details]
Bug 1634846 - P5. Fix data race on STS loop start. r?valentin,honza
Revision D81334 was moved to bug 1648898. Setting attachment 9159699 [details] to obsolete.
Comment 12•4 years ago
|
||
Comment on attachment 9159605 [details]
Bug 1634846 - P4. Make RemoteDecoder use a background taskqueue. r?mattwoodrow
Revision D81287 was moved to bug 1649294. Setting attachment 9159605 [details] to obsolete.
Comment 13•4 years ago
|
||
Comment 14•4 years ago
|
||
Backed out for webgl-conf crashes
Backout link: https://hg.mozilla.org/integration/autoland/rev/ed44d4e62140475b5daba4e7db38808dfea95960
Log link: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=307988602&repo=autoland&lineNumber=3484
Assignee | ||
Updated•4 years ago
|
Comment 15•4 years ago
|
||
Comment 16•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/681e77b6fe1b
https://hg.mozilla.org/mozilla-central/rev/ffa41c2b08b3
https://hg.mozilla.org/mozilla-central/rev/132e64564bdd
Updated•4 years ago
|
Description
•