Closed Bug 919244 Opened 11 years ago Closed 10 years ago

ghost-windows appears on https://apprtc.appspot.com/ after execute "Minimize memory usage"

Categories

(Core :: WebRTC: Audio/Video, defect)

x86_64
All
defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla29
Tracking Status
firefox27 --- wontfix
firefox28 --- verified
firefox29 --- verified
b2g-v1.3 --- fixed
b2g-v1.4 --- fixed

People

(Reporter: alice0775, Assigned: jib)

References

Details

(Whiteboard: [MemShrink:P2])

Attachments

(1 file, 1 obsolete file)

Steps To Reproduce.
1. Open https://apprtc.appspot.com/ in new tab
2. Close the tab
3. Open about:memory and Click "Measure"
   --- observe ghost-windows
4. Click "GC" and Click "Measure"
   --- observe ghost-windows
5. Click "CC" and Click "Measure"
   --- observe ghost-windows
6. Click "Minimize memory usage" and Click "Measure"
   --- observe ghost-windows

Actual Results:
After Step 6, Two ghost-windows appears
Whiteboard: [MemShrink]
Seems likely to be a webrtc issue.
Component: General → WebRTC
I failed to reproduce on Linux (trunk build, where I don't have a camera) or Mac (FF 24 beta, where I do).  Maybe it's a Windows-only issue?
I can also reproduce on ubuntu 12.04.
ttp://hg.mozilla.org/mozilla-central/rev/8b4d14afc4f6
Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0 ID:20130922030201
OS: Windows 7 → All
I didn't make a connection -- do you need to make a connection to reproduce?
(In reply to Nicholas Nethercote [:njn] from comment #4)
> I didn't make a connection -- do you need to make a connection to reproduce?

What is "connection"?

Just follow STR with new profile. 
It happens regardless of having camera or not.
I finally got this to repro on OS X also. One note on the STR is that the problem does not seem to arise if you acknowledge the microphone / camera doorhanger. You must close the page with that doorhanger open.

I also note that the issue will repro just fine using this test page, which uses gUM but not PeerConnection:

http://mozilla.github.io/webrtc-landing/gum_test.html

I used the "video-only" mode, but I suspect others have the same result. Assigning more specifically to "Audio/Video."
Component: WebRTC → WebRTC: Audio/Video
Ok, sounds like this is the cause of the leak that causes bug 917491 (same STR - don't answer a permission doorhanger; world leaks)
(In reply to Randell Jesup [:jesup] from comment #7)
> Ok, sounds like this is the cause of the leak that causes bug 917491 (same
> STR - don't answer a permission doorhanger; world leaks)

Sorry - not necessarily the same, but related
> One note on the STR is that the
> problem does not seem to arise if you acknowledge the microphone / camera
> doorhanger. You must close the page with that doorhanger open.

Ah, I acknowledged that before closing the tab.

Trying again, the doorhanger no long appears (even if I try a new profile?!) but I do get the 2 ghost windows.
jesup, ghost windows are pretty bad.  Any idea who might be able to work on this?
Whiteboard: [MemShrink] → [MemShrink:P2]
Blocks: 950165
The same thing is happening on chat.meatspac.es.  I looked at a log, and there are two nsXPCWrappedJS (nsIDOMGetUserMediaSuccessCallback) objects holding everything alive.  The XPCWJS has two references, one the self reference, and one unknown reference that is holding everything alive.
Seems related to Bug 949907.
jib: can you investigate this one?  At least to the point of deciding if it's related to bug 949907
Flags: needinfo?(jib)
Yes I'm looking at this one.
Assignee: nobody → jib
Flags: needinfo?(jib)
Two things needed to be fixed:

 1. OnNavigation now cleans up mActiveCallbacks (a coat-check for gUMRunnables)
 2. gUMRunnable now cleans up its JS callbacks unless it's "armed" for dispatch. 

I also added a comment on MediaManager's refcounting strategy for runnables off main:

 * GetUserMediaRunnable is meant for dispatch off main thread, where it would
 * be illegal to free JS callbacks. Therefore, it uses a rather risky strategy
 * of holding "already_AddRefed" references to the JS callbacks that must be
 * transfered and released in consequent dispatches arriving on main thread.
 *
 * A special Arm() method must be called before dispatch to enable this
 * behavior, because gUMRunnables are held in other circumstances.
Attachment #8356574 - Flags: review?(rjesup)
Comment on attachment 8356574 [details] [diff] [review]
Leakproof gUMRunnable + OnNavigation cleanup of MediaManager::mActiveCallbacks

Review of attachment 8356574 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/media/MediaManager.cpp
@@ +814,5 @@
>      }
>    }
>  
> +  void
> +  Arm() {

Comment what Arm() is doing (I know it's discussed above).

@@ +1666,5 @@
>      return NS_OK;
>  
>    } else if (!strcmp(aTopic, "getUserMedia:response:allow")) {
>      nsString key(aData);
> +    nsRefPtr<GetUserMediaRunnable> gUMRunnable;

Lets change gUMRunnable to gum_runnable to avoid confusion with the gFoo naming convention for globals.  (and below as well).  I realize it predated this change, but since we need to expand it and duplicate it, let's rename.
Attachment #8356574 - Flags: review?(rjesup) → review+
Added comments and renamed "gUMRunnable" to just "runnable" (which became available with this patch).

Carrying forward r+ from jesup.
Attachment #8356574 - Attachment is obsolete: true
Attachment #8357383 - Flags: review+
https://hg.mozilla.org/mozilla-central/rev/cad9ce8315a4
Status: NEW → RESOLVED
Closed: 10 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla29
Does this need backporting?
Flags: needinfo?(jib)
The leak has been there since the gUM permission prompt was introduced AFAIK, so it's not a regression per se. But clearly the sooner the fix appears in users' hands the better. What's customary?
Flags: needinfo?(jib)
Your call.
Flags: needinfo?(rjesup)
I'd say nominate it for Aurora.  Not a major problem if it's not accepted, as it's a memory leak issue.
Flags: needinfo?(rjesup)
This kind of memory leak is increasing cycle collections times, so it may cause significant jank.
Comment on attachment 8357383 [details] [diff] [review]
Leakproof gUMRunnable + OnNavigation cleanup of MediaManager::mActiveCallbacks (2) r=jesup

[Approval Request Comment]
Bug caused by (feature/regressing bug #): gUM permission prompt feature.
User impact if declined: Window leak. Increased cycle collection times, jank.
Testing completed (on m-c, etc.): Landed on m-c two weeks ago. Verified locally.
Risk to taking this patch (and alternatives if risky): Low. Just MediaManager, no dependencies.
String or IDL/UUID changes made by this patch: None
Attachment #8357383 - Flags: approval-mozilla-aurora?
Attachment #8357383 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Keywords: verifyme
Verified as fixed on Firefox 28 beta 1 (20140205162153) and latest Aurora 29.0a2 (20140205004001) under Win 7 64-bit, Ubuntu 32-bit and Mac OSX 10.8.5.
Status: RESOLVED → VERIFIED
Keywords: verifyme
QA Contact: petruta.rasa
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: