Last Comment Bug 655583 - about:memory: assertion: "Oops! You're asking for a weak reference to an object that doesn't support that." from nsObserverList::RemoveObserver
: about:memory: assertion: "Oops! You're asking for a weak reference to an obj...
Status: RESOLVED FIXED
:
Product: Toolkit
Classification: Components
Component: about:memory (show other bugs)
: unspecified
: x86_64 Linux
: -- normal (vote)
: mozilla6
Assigned To: Nicholas Nethercote [:njn]
:
Mentors:
Depends on:
Blocks: 633305
  Show dependency treegraph
 
Reported: 2011-05-08 06:41 PDT by Benoit Jacob [:bjacob] (mostly away)
Modified: 2011-07-08 01:26 PDT (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
patch (1.42 KB, patch)
2011-05-10 00:41 PDT, Nicholas Nethercote [:njn]
bzbarsky: review+
Details | Diff | Splinter Review

Description Benoit Jacob [:bjacob] (mostly away) 2011-05-08 06:41:23 PDT
Repeatedly reloading about:memory gave me this:

###!!! ASSERTION: Oops!  You're asking for a weak reference to an object that doesn't support that.: 'factoryPtr', file /home/bjacob/build/firefox/xpcom/build/nsWeakReference.cpp, line 109

Program received signal SIGTRAP, Trace/breakpoint trap.
RealBreak () at /home/bjacob/mozilla-central/xpcom/base/nsDebugImpl.cpp:413
413     }
(gdb) bt
#0  RealBreak () at /home/bjacob/mozilla-central/xpcom/base/nsDebugImpl.cpp:413
#1  0x00007ffff61c9337 in Break (
    aMsg=0x7fffffff9780 "###!!! ASSERTION: Oops!  You're asking for a weak reference to an object that doesn't support that.: 'factoryPtr', file /home/bjacob/build/firefox/xpcom/build/nsWeakReference.cpp, line 109") at /home/bjacob/mozilla-central/xpcom/base/nsDebugImpl.cpp:504
#2  0x00007ffff61c92fe in NS_DebugBreak_P (aSeverity=1, 
    aStr=0x7ffff6de5520 "Oops!  You're asking for a weak reference to an object that doesn't support that.", aExpr=0x7ffff6de5513 "factoryPtr", 
    aFile=0x7ffff6de54d8 "/home/bjacob/build/firefox/xpcom/build/nsWeakReference.cpp", aLine=109)
    at /home/bjacob/mozilla-central/xpcom/base/nsDebugImpl.cpp:380
#3  0x00007ffff613f61c in NS_GetWeakReference (aInstancePtr=0x7fffde812da0, aErrorPtr=0x0)
    at /home/bjacob/build/firefox/xpcom/build/nsWeakReference.cpp:109
#4  0x00007ffff4aee9a4 in do_GetWeakReference (aRawPtr=0x7fffde812da0, error=0x0)
    at ../../../dist/include/nsIWeakReferenceUtils.h:112
#5  0x00007ffff6165a89 in nsObserverList::RemoveObserver (this=0x1612ef0, 
    anObserver=0x7fffde812da0) at /home/bjacob/mozilla-central/xpcom/ds/nsObserverList.cpp:76
#6  0x00007ffff61676c4 in nsObserverService::RemoveObserver (this=0x775b10, 
    anObserver=0x7fffde812da0, aTopic=0x7fffdc775fa0 "child-memory-reporter-update")
    at /home/bjacob/mozilla-central/xpcom/ds/nsObserverService.cpp:153
#7  0x00007ffff61d902a in NS_InvokeByIndex_P (that=0x775b10, methodIndex=4, paramCount=2, 
    params=0x7fffffff9f30)
    at /home/bjacob/mozilla-central/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_x86_64_unix.cpp:195
#8  0x00007ffff5a11498 in CallMethodHelper::Invoke (this=0x7fffffff9ef0)
    at /home/bjacob/mozilla-central/js/src/xpconnect/src/xpcwrappednative.cpp:3141
#9  0x00007ffff5a0f48d in CallMethodHelper::Call (this=0x7fffffff9ef0)
    at /home/bjacob/mozilla-central/js/src/xpconnect/src/xpcwrappednative.cpp:2407
#10 0x00007ffff5a0b57c in XPCWrappedNative::CallMethod (ccx=..., 
---Type <return> to continue, or q <return> to quit---
    mode=XPCWrappedNative::CALL_METHOD)
    at /home/bjacob/mozilla-central/js/src/xpconnect/src/xpcwrappednative.cpp:2371
#11 0x00007ffff5a1b2d2 in XPC_WN_CallMethod (cx=0x1206d60, argc=2, vp=0x7fffe2a75118)
    at /home/bjacob/mozilla-central/js/src/xpconnect/src/xpcwrappednativejsops.cpp:1610
#12 0x00007ffff667aa2c in js::CallJSNative (cx=0x1206d60, 
    native=0x7ffff5a1b05f <XPC_WN_CallMethod(JSContext*, unsigned int, jsval_layout*)>, argc=2, 
    vp=0x7fffe2a75118) at /home/bjacob/mozilla-central/js/src/jscntxtinlines.h:277
#13 0x00007ffff68d7e3a in js::Interpret (cx=0x1206d60, entryFrame=0x7fffe2a75050, 
    inlineCallCount=1, interpMode=js::JSINTERP_NORMAL)
    at /home/bjacob/mozilla-central/js/src/jsinterp.cpp:4664
#14 0x00007ffff6675f12 in js::RunScript (cx=0x1206d60, script=0x7fffdd24a520, fp=0x7fffe2a75050)
    at /home/bjacob/mozilla-central/js/src/jsinterp.cpp:603
#15 0x00007ffff66763ab in js::Invoke (cx=0x1206d60, argsRef=..., option=js::INVOKE_NORMAL)
    at /home/bjacob/mozilla-central/js/src/jsinterp.cpp:684
#16 0x00007ffff66769f1 in js::ExternalInvoke (cx=0x1206d60, thisv=..., fval=..., argc=1, 
    argv=0x7fffdc097790, rval=0x7fffffffc0c0)
    at /home/bjacob/mozilla-central/js/src/jsinterp.cpp:806
#17 0x00007ffff65d69b2 in JS_CallFunctionValue (cx=0x1206d60, obj=0x7fffe0535d80, fval=..., 
    argc=1, argv=0x7fffdc097790, rval=0x7fffffffc0c0)
    at /home/bjacob/mozilla-central/js/src/jsapi.cpp:5079
#18 0x00007ffff5443271 in nsJSContext::CallEventHandler (this=0x120aaa0, aTarget=0x7fffdd47f678, 
    aScope=0x7fffe0535d80, aHandler=0x7fffc3b02d68, aargv=0x7fffdd430520, arv=0x7fffffffc290)
    at /home/bjacob/mozilla-central/dom/base/nsJSEnvironment.cpp:1903
#19 0x00007ffff54dbfdb in nsJSEventListener::HandleEvent (this=0x7fffdd221a70, 
    aEvent=0x7fffdd1cc6f0)
    at /home/bjacob/mozilla-central/dom/src/events/nsJSEventListener.cpp:224
#20 0x00007ffff52227c5 in nsEventListenerManager::HandleEventSubType (this=0x7fffdcde2980, 
    aListenerStruct=0x7fffdcde29f0, aListener=0x7fffdd221a70, aDOMEvent=0x7fffdd1cc6f0, 
---Type <return> to continue, or q <return> to quit---
    aCurrentTarget=0x7fffdd47f698, aPhaseFlags=6, aPusher=0x7fffffffc960)
    at /home/bjacob/mozilla-central/content/events/src/nsEventListenerManager.cpp:1141
#21 0x00007ffff5222c80 in nsEventListenerManager::HandleEventInternal (this=0x7fffdcde2980, 
    aPresContext=0x7fffdd47ee10, aEvent=0x7fffffffcad0, aDOMEvent=0x7fffffffc930, 
    aCurrentTarget=0x7fffdd47f698, aFlags=6, aEventStatus=0x7fffffffc938, aPusher=0x7fffffffc960)
    at /home/bjacob/mozilla-central/content/events/src/nsEventListenerManager.cpp:1236
#22 0x00007ffff524edf9 in nsEventListenerManager::HandleEvent (this=0x7fffdcde2980, 
    aPresContext=0x7fffdd47ee10, aEvent=0x7fffffffcad0, aDOMEvent=0x7fffffffc930, 
    aCurrentTarget=0x7fffdd47f698, aFlags=6, aEventStatus=0x7fffffffc938, aPusher=0x7fffffffc960)
    at /home/bjacob/mozilla-central/content/events/src/nsEventListenerManager.h:146
#23 0x00007ffff524f329 in nsEventTargetChainItem::HandleEvent (this=0xe40090, aVisitor=..., 
    aFlags=6, aMayHaveNewListenerManagers=0, aPusher=0x7fffffffc960)
    at /home/bjacob/mozilla-central/content/events/src/nsEventDispatcher.cpp:215
#24 0x00007ffff524cd3c in nsEventTargetChainItem::HandleEventTargetChain (this=0xe3fed0, 
    aVisitor=..., aFlags=6, aCallback=0x0, aMayHaveNewListenerManagers=0, aPusher=0x7fffffffc960)
    at /home/bjacob/mozilla-central/content/events/src/nsEventDispatcher.cpp:344
#25 0x00007ffff524db58 in nsEventDispatcher::Dispatch (aTarget=0x1206a80, 
    aPresContext=0x7fffdd47ee10, aEvent=0x7fffffffcad0, aDOMEvent=0x0, 
    aEventStatus=0x7fffffffcb1c, aCallback=0x0, aTargets=0x0)
    at /home/bjacob/mozilla-central/content/events/src/nsEventDispatcher.cpp:648
#26 0x00007ffff4db1e79 in DocumentViewerImpl::PageHide (this=0x7fffdefa4580, aIsUnload=1)
    at /home/bjacob/mozilla-central/layout/base/nsDocumentViewer.cpp:1302
#27 0x00007ffff5af203e in nsDocShell::FirePageHideNotification (this=0x1205c50, aIsUnload=1)
    at /home/bjacob/mozilla-central/docshell/base/nsDocShell.cpp:1516
#28 0x00007ffff5b0892c in nsDocShell::CreateContentViewer (this=0x1205c50, 
    aContentType=0x7fffdcb2f1e8 "application/xhtml+xml", request=0x7fffdd41f760, 
    aContentHandler=0x7fffdcb2f770)
    at /home/bjacob/mozilla-central/docshell/base/nsDocShell.cpp:7376
---Type <return> to continue, or q <return> to quit---
#29 0x00007ffff5b247ec in nsDSURIContentListener::DoContent (this=0x12065e0, 
    aContentType=0x7fffdcb2f1e8 "application/xhtml+xml", aIsContentPreferred=0, 
    request=0x7fffdd41f760, aContentHandler=0x7fffdcb2f770, aAbortProcess=0x7fffffffce3c)
    at /home/bjacob/mozilla-central/docshell/base/nsDSURIContentListener.cpp:148
#30 0x00007ffff5b2cfa0 in nsDocumentOpenInfo::TryContentListener (this=0x7fffdcb2f750, 
    aListener=0x12065e0, aChannel=0x7fffdd41f760)
    at /home/bjacob/mozilla-central/uriloader/base/nsURILoader.cpp:757
#31 0x00007ffff5b2bb95 in nsDocumentOpenInfo::DispatchContent (this=0x7fffdcb2f750, 
    request=0x7fffdd41f760, aCtxt=0x0)
    at /home/bjacob/mozilla-central/uriloader/base/nsURILoader.cpp:455
#32 0x00007ffff5b2b137 in nsDocumentOpenInfo::OnStartRequest (this=0x7fffdcb2f750, 
    request=0x7fffdd41f760, aCtxt=0x0)
    at /home/bjacob/mozilla-central/uriloader/base/nsURILoader.cpp:295
#33 0x00007ffff4ad2311 in nsBaseChannel::OnStartRequest (this=0x7fffdd41f710, 
    request=0x7fffdd26d610, ctxt=0x0)
    at /home/bjacob/mozilla-central/netwerk/base/src/nsBaseChannel.cpp:712
#34 0x00007ffff4ae7248 in nsInputStreamPump::OnStateStart (this=0x7fffdd26d610)
    at /home/bjacob/mozilla-central/netwerk/base/src/nsInputStreamPump.cpp:441
#35 0x00007ffff4ae706e in nsInputStreamPump::OnInputStreamReady (this=0x7fffdd26d610, 
    stream=0x7fffdd26d6b8)
    at /home/bjacob/mozilla-central/netwerk/base/src/nsInputStreamPump.cpp:397
#36 0x00007ffff618d9e1 in nsInputStreamReadyEvent::Run (this=0x7fffdcb2f260)
    at /home/bjacob/mozilla-central/xpcom/io/nsStreamUtils.cpp:114
#37 0x00007ffff61b88b0 in nsThread::ProcessNextEvent (this=0x6e12c0, mayWait=0, 
    result=0x7fffffffd51c) at /home/bjacob/mozilla-central/xpcom/threads/nsThread.cpp:618
#38 0x00007ffff6143904 in NS_ProcessNextEvent_P (thread=0x6e12c0, mayWait=0)
    at /home/bjacob/build/firefox/xpcom/build/nsThreadUtils.cpp:250
#39 0x00007ffff600ea98 in mozilla::ipc::MessagePump::Run (this=0x6c5d20, aDelegate=0x6c5e50)
---Type <return> to continue, or q <return> to quit---
    at /home/bjacob/mozilla-central/ipc/glue/MessagePump.cpp:110
#40 0x00007ffff62182a7 in MessageLoop::RunInternal (this=0x6c5e50)
    at /home/bjacob/mozilla-central/ipc/chromium/src/base/message_loop.cc:218
#41 0x00007ffff6218238 in MessageLoop::RunHandler (this=0x6c5e50)
    at /home/bjacob/mozilla-central/ipc/chromium/src/base/message_loop.cc:202
#42 0x00007ffff62181c9 in MessageLoop::Run (this=0x6c5e50)
    at /home/bjacob/mozilla-central/ipc/chromium/src/base/message_loop.cc:176
#43 0x00007ffff5ea8663 in nsBaseAppShell::Run (this=0x6f3ca0)
    at /home/bjacob/mozilla-central/widget/src/xpwidgets/nsBaseAppShell.cpp:189
#44 0x00007ffff5be8933 in nsAppStartup::Run (this=0x971410)
    at /home/bjacob/mozilla-central/toolkit/components/startup/nsAppStartup.cpp:224
#45 0x00007ffff4a8f9c6 in XRE_main (argc=5, argv=0x7fffffffe178, aAppData=0x608cb0)
    at /home/bjacob/mozilla-central/toolkit/xre/nsAppRunner.cpp:3698
#46 0x000000000040115c in main (argc=5, argv=0x7fffffffe178)
    at /home/bjacob/mozilla-central/browser/app/nsBrowserApp.cpp:158
Comment 1 Boris Zbarsky [:bz] 2011-05-08 06:49:56 PDT
Chances are, we're calling removeObserver(ChildMemoryListener) when it's not actually registered as an observer.

Do you actually get a crash?  Or just an assertion?
Comment 2 Benoit Jacob [:bjacob] (mostly away) 2011-05-08 07:27:07 PDT
Sorry, this is only an assertion, not a crash.
Comment 3 Nicholas Nethercote [:njn] 2011-05-08 18:31:33 PDT
bz, aboutMemory.js has this code:

  function onLoad()
  {
    var os = Cc["@mozilla.org/observer-service;1"].
        getService(Ci.nsIObserverService);
    os.notifyObservers(null, "child-memory-reporter-request", null);

    os.addObserver(ChildMemoryListener, "child-memory-reporter-update", false);

    update();
  }

  function onUnload()
  {
    var os = Cc["@mozilla.org/observer-service;1"].
        getService(Ci.nsIObserverService);
    os.removeObserver(ChildMemoryListener, "child-memory-reporter-update");
  }

Is it possible that addObserver might fail?  (nsIObserverService.idl doesn't indicate it can.)  Might onLoad() fail to run sometimes?

Should os.removeObserver() be preceded by some kind of test of whether ChildMemoryListener is an observer?
Comment 4 Boris Zbarsky [:bz] 2011-05-09 13:43:06 PDT
> Might onLoad() fail to run sometimes?

Yes.  If you unload the page before it's done loading, we will run onUnload but not onLoad in this case.

Probably best to just set a boolean flag in onLoad after we add the observer and check it before removing in onUnload.
Comment 5 Nicholas Nethercote [:njn] 2011-05-09 21:05:23 PDT
I can't reproduce that assertion, but I can trigger this in the error console by holding down ctrl-r:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIObserverService.removeObserver]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: chrome://global/content/aboutMemory.js :: onUnload :: line 64"  data: no]
Comment 6 Nicholas Nethercote [:njn] 2011-05-10 00:41:04 PDT
Created attachment 531260 [details] [diff] [review]
patch

bz, this implements your flag suggestion.  With it applied I couldn't replicate the exception even after holding down ctrl-r for 30 seconds;  prior to the patch I would have seen it many times if I did that.
Comment 7 Boris Zbarsky [:bz] 2011-05-10 09:52:08 PDT
Comment on attachment 531260 [details] [diff] [review]
patch

r=me
Comment 8 :Gavin Sharp [email: gavin@gavinsharp.com] 2011-05-10 10:10:38 PDT
nit: put the getService call inside the if() block as well
Comment 9 Nicholas Nethercote [:njn] 2011-05-11 21:02:11 PDT
http://hg.mozilla.org/mozilla-central/rev/0b9b70e20848

Note You need to log in before you can comment on or make changes to this bug.