Closed Bug 1529811 Opened 5 years ago Closed 3 months ago

Allow strong references to IPDL actors that support async methods with return values to outlive the actors' lifetimes

Categories

(Core :: IPC, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED

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

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).

Depends on: 1509143
Priority: -- → P3
See Also: → 1443748

I think this might be doable with the changes in bug 1540731, but I'm not super confident about that.

Depends on: 1540731
Severity: normal → S3

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.

Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.