Allow strong references to IPDL actors that support async methods with return values to outlive the actors' lifetimes
Categories
(Core :: IPC, enhancement, P3)
Tracking
()
People
(Reporter: perry, Unassigned)
References
(Depends on 1 open bug)
Details
Actors that support async return values, i.e. have a IPDL method of the form "async Method() returns (ReturnValue aValue);", inherit from SupportsWeakPtr. Given the current logic in SupportsWeakPtr, such actors' destructors (their C++ destructors, not ActorDestroy) must be called on their owning thread. This presents a problem for when an actor would like to also support thread safe reference counting, as the last strong reference to the actor must be dropped on the owning thread, even if the consumer of the reference doesn't use any IPDL mechanisms. Additionally, it can't always be clear when a strong reference is the last strong reference.
The current and clearest ways to circumvent this issue are:
- Proxy release any strong reference that doesn't exist on the owning thread that can possibly be the last strong reference, or
- have the concrete actor class support thread safe weak pointers, and only capture off-owning-thread references to the actor as thread safe weak pointers.
However, both of those strategies seem very cumbersome and are prone to forgetting to handle an existing/new reference.
One of the proposed strategies is for these actors to use composition instead of inheritance to handle their weak pointers/references; this way detaching from the weak reference can be tied to ActorDestroy rather than C++ object destruction.
An example of this issue is RemoteWorkerChild, which will in the near future have async IPDL methods with return values and has off-owning-thread strong references, such as https://searchfox.org/mozilla-central/rev/b36e97fc776635655e84f2048ff59f38fa8a4626/dom/workers/remoteworkers/RemoteWorkerChild.cpp#337
Comment 1•5 years ago
|
||
This was discussed in IPC bug triage, and the conclusion as I understand it was that this would essentially depend on requiring actors to be refcounted (which also useful for other reasons, but it's complicated and difficult to retrofit onto existing actors).
Comment 2•5 years ago
|
||
I think this might be doable with the changes in bug 1540731, but I'm not super confident about that.
Updated•2 years ago
|
Comment 3•3 months ago
|
||
IPDL actors with async return haven't implemented SupportsWeakPtr
in a while. We instead use WeakActorLifecycleProxy
(added in bug 1563624), which doesn't have the issues mentioned in this bug.
Description
•