Closed Bug 919429 Opened 13 years ago Closed 13 years ago

[Message manager] We must not force weak listeners to implement Ci.nsIMessageListener

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla27
blocking-b2g koi+
Tracking Status
firefox25 --- wontfix
firefox26 --- fixed
firefox27 --- fixed
b2g-v1.2 --- fixed

People

(Reporter: ferjm, Assigned: ferjm)

References

Details

(Whiteboard: [qa-])

Attachments

(3 files)

Attached patch Gecko patch — — Splinter Review
I've being doing some tests with |addWeakMessageManager| and I find myself in a situation where a weak listener is being removed as soon as the first message is received. The attached patches are: 1- Gecko mod: a few debug statements (B2G only) and a quick hack on the Webapps API which adds a weak listener for the "Webapps:GetSelf:Return:OK" message with every |.getSelf| call and removes this listener when the message is received in the child side. 2- Gaia test: a mozApps.getSelf test call. The logs that I get with these patches applied are the following: I/Gecko ( 1670): === getSelf I/Gecko ( 1670): AddWeakMessageListener Webapps:GetSelf:Return:OK I/Gecko ( 1534): ReceiveMessage Webapps:GetSelf I/Gecko ( 1534): Got Webapps:GetSelf I/Gecko ( 1534): sendAsyncMessage Webapps:GetSelf:Return:OK I/Gecko ( 1670): ReceiveMessage Webapps:GetSelf:Return:OK I/Gecko ( 1670): ===== Removing expired weak listener Webapps:GetSelf:Return:OK ======! E/GeckoConsole( 1670): Content JS LOG at app://getselftest.gaiamobile.org/test.js:4 in test: Calling getSelf As you can see, the listener is being removed with the first message received, even if this message is exactly the one being listener, and the "Webapps:GetSelf:Return:OK" message is never received in the child (1670). Adding a non-weak listener gives the following output, where the listener is not being removed and the messages are received in the child side as expected: I/Gecko ( 1845): === getSelf I/Gecko ( 1845): AddMessageListener Webapps:GetSelf:Return:OK I/Gecko ( 1719): ReceiveMessage Webapps:GetSelf I/Gecko ( 1719): Got Webapps:GetSelf I/Gecko ( 1719): sendAsyncMessage Webapps:GetSelf:Return:OK I/Gecko ( 1845): ReceiveMessage Webapps:GetSelf:Return:OK I/Gecko ( 1845): Got Webapps:GetSelf:Return:OK I/Gecko ( 1719): ReceiveMessage Webapps:RegisterForMessages E/GeckoConsole( 1845): Content JS LOG at app://getselftest.gaiamobile.org/test.js:4 in test: Calling getSelf E/GeckoConsole( 1845): Content JS LOG at app://getselftest.gaiamobile.org/test.js:6 in anonymous: We never get here :( I wonder if this is actually the expected behavior or if the message manager is being too aggressive removing the weak listeners. Unfortunately, I couldn't find out yet if the listener is being GC'ed.
Attached file Gaia test —
Attachment #808456 - Attachment description: weakreftest.patch → Gecko patch
Assignee: nobody → ferjmoreno
Summary: [Message manager] Weak listener removed with the first received message → [Message manager] Objects adding weak listeners must implement Ci.nsIMessageListener
Blocks: 915598
Just for posterity here, the issue is that if you pass a JS object to a method that takes an nsIMessageListener, XPConnect will do the implicit conversion for you. But if you pass it to a method that takes an nsISupports and explicitly call QI on it, that will fail.
(In reply to Fernando Jiménez Moreno [:ferjm] (needinfo, please) from comment #0) > I/Gecko ( 1670): === getSelf > I/Gecko ( 1670): AddWeakMessageListener Webapps:GetSelf:Return:OK > I/Gecko ( 1534): ReceiveMessage Webapps:GetSelf > I/Gecko ( 1534): Got Webapps:GetSelf > I/Gecko ( 1534): sendAsyncMessage Webapps:GetSelf:Return:OK > I/Gecko ( 1670): ReceiveMessage Webapps:GetSelf:Return:OK > I/Gecko ( 1670): ===== Removing expired weak listener > Webapps:GetSelf:Return:OK ======! > E/GeckoConsole( 1670): Content JS LOG at > app://getselftest.gaiamobile.org/test.js:4 in test: Calling getSelf > > As you can see, the listener is being removed with the first message > received, even if this message is exactly the one being listener, and the > "Webapps:GetSelf:Return:OK" message is never received in the child (1670). This looks ok to me. When the weak listener is "removed", it means the object it points to has already gone away. > I wonder if this is actually the expected behavior or if the message manager > is being too aggressive removing the weak listeners. Unfortunately, I > couldn't find out yet if the listener is being GC'ed. Well, if weakListener = do_QueryReferent(mListeners[i].mWeakListener); causes weakListener to be null, the listener is either dead or the listener doesn't have the right QI... ahaa, that is why the summary was changed.
Summary: [Message manager] Objects adding weak listeners must implement Ci.nsIMessageListener → [Message manager] We must not force weak listeners to implement Ci.nsIMessageListener
FWIW I disagree with the latest title of this bug. Forcing them to implement it explicitly is fine as long as the failure behavior is easy to understand.
If strong listeners don't have to QI to nsIMessageListener, weak listeners shouldn't either.
Attached patch v1 — — Splinter Review
Olli's argument sounds good enough to me
Attachment #808530 - Flags: review?(bugs)
Attachment #808530 - Flags: review?(bugs) → review+
This is blocking a potential koi+ issue. Please see bug 915598, comment #16. Nominating for koi+.
blocking-b2g: --- → koi?
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
blocking-b2g: koi? → koi+
Whiteboard: [qa-]
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: