Closed Bug 574127 Opened 14 years ago Closed 14 years ago

dead/broken code in HUD_SERVICE.shutdown

Categories

(DevTools :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 595350

People

(Reporter: Gavin, Assigned: ddahl)

References

Details

Attachments

(1 file, 3 obsolete files)

Blocks: 529086
sorry gavin, did not see this as my bz query was lazer focused on bugs blocking 529086. i better change that.
Assignee: nobody → ddahl
Attached patch patch v1 (obsolete) — Splinter Review
Not sure if all of this is needed. For instance if there is no main xul window open, the HUDService object is probably GC'd already, no?
Attachment #458454 - Flags: review?(dtownsend)
Comment on attachment 458454 [details] [diff] [review]
patch v1

>diff --git a/toolkit/components/console/hudservice/HUDService.jsm b/toolkit/components/console/hudservice/HUDService.jsm
>--- a/toolkit/components/console/hudservice/HUDService.jsm
>+++ b/toolkit/components/console/hudservice/HUDService.jsm
>@@ -496,32 +496,59 @@ HUD_SERVICE.prototype =
> 
>   /**
>    * Shutdown all HeadsUpDisplays on xpcom-shutdown
>    *
>    * @returns void
>    */
>   shutdown: function HS_shutdown()
>   {
>-    for (var displayId in this._headsUpDisplays) {
>-      this.unregisterDisplay(displayId);
>-    }
>-    // delete the storage as it holds onto channels
>-    delete this.storage;
>-
>-     var xulWindow = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
>+    var xulWindow;
>+    var contentWindow;

Just declare these at first use, JS vars are function scoped anyway.

>+    // We need to get a contentWindow, any contentWindow to get a XUL window reference
>+    for (var idx in this.hudWeakReferences) {
>+      // you are never sure if your weakRef will exist
>+      try {
>+        contentWindow = this.hudWeakReferences[idx].get().contentWindow;
>+      }
>+      catch (ex) {
>+        // noop: .get() will throw if the weakRef is gone
>+      }

get() does not throw if the reference is gone, it will merely return null. Test that and get rid of the try catch block.

>+
>+      if (contentWindow) {
>+        break;
>+      }
>+    }
>+
>+    if (contentWindow) {
>+      // only run this xul window routine if there are any actual tabs open
>+      // this will alos fail if the contentWindow goes away inside of this
>+      // method.
>+      try {
>+        xulWindow = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
>        .getInterface(Ci.nsIWebNavigation)
>        .QueryInterface(Ci.nsIDocShellTreeItem)
>        .rootTreeItem
>        .QueryInterface(Ci.nsIInterfaceRequestor)
>        .getInterface(Ci.nsIDOMWindow);

The indentation is messed up here, did you diff with -w?

This is all happening at xpcom-shutdown right? No windows should exist at that point so this all seems to be over the top. If they do then you have to account for the fact that there may be multiple windows existing, this code seems to only handle the first one it comes across.
Attachment #458454 - Flags: review?(dtownsend) → review-
Attached patch v 2 shutdown-patch (obsolete) — Splinter Review
seems to fix any hang-around leaks...
Attachment #458454 - Attachment is obsolete: true
Attachment #474224 - Flags: review?
Attachment #474224 - Flags: feedback?(pwalton)
Attachment #474224 - Flags: review? → review?(sdwilsh)
Attached patch v 2 shutdown-patch (obsolete) — Splinter Review
Attachment #474224 - Attachment is obsolete: true
Attachment #474227 - Flags: review?(sdwilsh)
Attachment #474227 - Flags: feedback?(pwalton)
Attachment #474224 - Flags: review?(sdwilsh)
Attachment #474224 - Flags: feedback?(pwalton)
Attachment #474227 - Attachment is patch: true
Attachment #474227 - Attachment mime type: application/octet-stream → text/plain
Comment on attachment 474227 [details] [diff] [review]
v 2 shutdown-patch

LGTM.
Attachment #474227 - Flags: feedback?(pwalton) → feedback+
Should this have a test?
added unregister.bind(this) to provide the correct scope
Attachment #474227 - Attachment is obsolete: true
Attachment #474238 - Flags: review?(sdwilsh)
Attachment #474238 - Flags: feedback?(pwalton)
Attachment #474227 - Flags: review?(sdwilsh)
(In reply to comment #8)
> Should this have a test?

You cannot test stuff on shutdown:(
blocking2.0: --- → ?
The weird thing is that the leak disappears with this patch on Linux but is still there on windows, but seems less severe.
Blocks: devtools4b7
Comment on attachment 474238 [details] [diff] [review]
v 3 shutdown patch

This doesn't fix the leak. The problem is that the console isn't unregistered when new windows are closed with the console still open. The quit event isn't what you want: instead, you want the window close event (which is fired on application quit as well as on manual window close).
Attachment #474238 - Flags: feedback?(pwalton) → feedback-
(In reply to comment #12)
> you want the window close event (which is fired on
> application quit as well as on manual window close).

Ok, HUDService.onTabClose handles tab closure, which is called on each tab as Firefox shuts down. I guess we do not handle the situation where a console is opened and closed but the tab remains open. That must be the (one of) leak(s).
Why do we need to hold the release for this? Please explain why blocking is needed when making the request.
(In reply to comment #14)
> Why do we need to hold the release for this? Please explain why blocking is
> needed when making the request.

I should just ask for approval once I have r+. Just want to land it asap.
blocking2.0: ? → ---
(In reply to comment #13)
> Ok, HUDService.onTabClose handles tab closure, which is called on each tab as
> Firefox shuts down. I guess we do not handle the situation where a console is
> opened and closed but the tab remains open. That must be the (one of) leak(s).
Does that mean that this isn't ready?
(In reply to comment #16)
> Does that mean that this isn't ready?

no. It means I need to file another bug for handling the reference eradication on closed consoles. I thought we handled everything, but of course, this code has changed a lot since I wrote the console close routine.
Comment on attachment 474238 [details] [diff] [review]
v 3 shutdown patch

>   /**
>-   * Shutdown all HeadsUpDisplays on xpcom-shutdown
>+   * Shutdown all HeadsUpDisplays on quit-application-granted
nit: punctuation please :)

>+    // remove all event listeners that we created
ditto

>+    let windowEnum = Services.wm.getEnumerator("navigator:browser");
>+    while (windowEnum.hasMoreElements()) {
>+      let window = windowEnum.getNext();
>+      let gBrowser = window.gBrowser;
>+      gBrowser.tabContainer.removeEventListener("TabClose",
>+						this.onTabClose, false);
TABS!

>+    Services.obs.addObserver(this, "quit-application-granted", false);
You use/reference the quit-application-granted topic in several places.  constifiy it globally, and use the constant please.

r=sdwilsh with those changes
Attachment #474238 - Flags: review?(sdwilsh) → review+
(In reply to comment #18)
> >+    let windowEnum = Services.wm.getEnumerator("navigator:browser");
> >+    while (windowEnum.hasMoreElements()) {
> >+      let window = windowEnum.getNext();
> >+      let gBrowser = window.gBrowser;
> >+      gBrowser.tabContainer.removeEventListener("TabClose",
> >+						this.onTabClose, false);
> TABS!

How embarassing. I think that is due to the emacs on my windoze box, which needs some .emacs tweaks.
(In reply to comment #17)
> (In reply to comment #16)
> > Does that mean that this isn't ready?
> 
> no. It means I need to file another bug for handling the reference eradication
> on closed consoles. I thought we handled everything, but of course, this code
> has changed a lot since I wrote the console close routine.

The patches in bug 595350 should handle this.
(In reply to comment #13)
> (In reply to comment #12)
> > you want the window close event (which is fired on
> > application quit as well as on manual window close).
> 
> Ok, HUDService.onTabClose handles tab closure, which is called on each tab as
> Firefox shuts down.

Just tested and unfortunately this doesn't seem to be the case. You have to listen for the window close event explicitly.
Blocks: devtools4b8
No longer blocks: devtools4b7
this has an r+'d patch sitting here and blocks 606055. Is that patch still valid?
Blocks: 606055
Pretty sure this bug should now be a dupe of bug 595350 http://hg.mozilla.org/mozilla-central/rev/b2cb6f8e4840
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: