Ensure that all nsIChannels release as many references as possible during OnStopRequest

Assigned to



4 years ago
8 months ago


(Reporter: jduell, Assigned: johnsullivan.pem)


Firefox Tracking Flags

(Not tracked)


(Whiteboard: [necko-backlog])


(1 attachment, 1 obsolete attachment)

Per bug 1015662 comment 14 and 15, we should audit all nsIChannels (not just in /netwerk, but also things like nsJARChannel, nsJSChannel, and even JS implementations if there are any) and make sure that they all release references in OnStopRequest to at least (mListener, mListenerContext, mCallbacks, mLoadGroup (rather than just removing the channel from the loadGroup yet keeping the mLoadGroup pointer), and possibly mOwner.

Adding some sort of FreeReferences() function in nsBaseChannel and HttpBaseChannel might be a good idea here.

If anyone can think of additional things to throw in the list, chime in.

Comment 1

4 years ago
bz: is it OK to null out mOwner in onStopRequest?
Flags: needinfo?(bzbarsky)
Not obviously.  getChannelPrincipal depends on mOwner, and I don't have very good confidence that it's never called after necko has called OnStopRequest.  Most simply, extensions can install streamlisteners via nsITraceableChannel and delay delivery of all the streamlistener callbacks to their final recipient.  :(
Flags: needinfo?(bzbarsky)


4 years ago
Assignee: nobody → josullivan

Comment 3

4 years ago
Created attachment 8465030 [details] [diff] [review]
Potential Patch

I'm still not super confident I audited all the necessary code, but I did look at every file that had all of the terms OnStopRequest, mListener, mListenerContext, and mCallbacks in it. I'm also not super confident that I know what these channels are used for.

I did create a patch that passes `./mach xpcshell-test netwerk/test` (there's a failure on the tip of master already that was unaffected by my change though), and navigating around with the browser works fine.

What do you think?
Attachment #8465030 - Flags: feedback?(sworkman)
Attachment #8465030 - Flags: feedback?(jduell.mcbugs)
Comment on attachment 8465030 [details] [diff] [review]
Potential Patch

Review of attachment 8465030 [details] [diff] [review]:

This looks like the right kind of thing to me. But I'm going to defer to Jason because he knows these channels better than I do :)

Push a build to try with xpcshell tests and mochitests for one or two platforms to see what happens.

::: modules/libjar/nsJARChannel.cpp
@@ +1010,2 @@
>      }
> +    mListenerContext = 0;

Attachment #8465030 - Flags: feedback?(sworkman) → feedback+

Comment 5

4 years ago
Comment on attachment 8465030 [details] [diff] [review]
Potential Patch

Review of attachment 8465030 [details] [diff] [review]:

Looks like you forgot HttpChannelChild?


We don't free mLoadGroup or mCallbacks there.

Also, have you looked outside /netwerk?   The code that start this little project (nsJSProtocolHandler--see bug 1015662) still needs to be fixed, too:


There may be other weird nsIChannel implementations that we don't know about.  Try grepping the tree for "public nsIChannel" and '->OnStopRequest' (for C++ code) and '.onStopRequest' (for JS) 

I'm +r-ing this patch (fix the 2 nits and you can just mark the next version +r and obsolete this one).  Let's do the rest of this bug in a separate patch so there's no need to re-review what you've done so far, which all looks good.  That said, a try run is definitely a good idea :)

::: netwerk/protocol/ftp/FTPChannelChild.cpp
@@ +484,5 @@
>      mIsPending = false;
>      AutoEventEnqueuer ensureSerialDispatch(mEventQ);
> +
> +    if (mListener) {
> +      (void)mListener->OnStopRequest(this, mListenerContext, aChannelStatus);

Might as well get rid of old K&R style "(void)": that's very old school and not used generally in Mozilla code.

@@ +491,3 @@
>      mListenerContext = nullptr;
> +    mCallbacks = nullptr;

No need for blank line between Context = null and callbacks=null
Attachment #8465030 - Flags: feedback?(jduell.mcbugs) → review+

Comment 6

4 years ago
Created attachment 8492458 [details] [diff] [review]
Bug 1021114.patch

This is my last day and I unfortunately never got back to this because a couple other bugs were placed at a higher priority, but I did make the changes requested and had trouble getting it through try. My notes on this were:

> I can't tell why the mochitest failed. I got Hit `MOZ_CRASH(DOMFile not thread-safe) at
> c:\Users\johnsullivan\Desktop\gecko-dev\content\base\src\nsDOMFile.cpp:155`. But here's also
> some `###!!! [Child][MessageChannel] Error: Channel error: cannot send/recv`.

It seems we have to be extra careful about which variables we null. Regardless, this patch is what I had at the moment. Whoever picks this up should start with this because it'll save you some time finding what areas of the code need to be touched. The last time I sent it through try it failed though, so keep that in mind.
Attachment #8465030 - Attachment is obsolete: true
Whiteboard: [necko-backlog]
You need to log in before you can comment on or make changes to this bug.