Last Comment Bug 784591 - don't leave around decoded image data for display: none images
: don't leave around decoded image data for display: none images
Status: RESOLVED FIXED
[MemShrink:P2]
:
Product: Core
Classification: Components
Component: DOM (show other bugs)
: Trunk
: All All
: -- normal with 4 votes (vote)
: mozilla21
Assigned To: Timothy Nikkel (:tnikkel)
:
: Andrew Overholt [:overholt]
Mentors:
: 761113 (view as bug list)
Depends on: 832571 1061894
Blocks: 689623 761113 791731 843213
  Show dependency treegraph
 
Reported: 2012-08-21 21:57 PDT by Timothy Nikkel (:tnikkel)
Modified: 2014-09-03 14:45 PDT (History)
19 users (show)
ryanvm: in‑testsuite-
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
part 1 (8.04 KB, patch)
2012-08-21 21:59 PDT, Timothy Nikkel (:tnikkel)
no flags Details | Diff | Splinter Review
part 2 (7.56 KB, patch)
2012-08-21 21:59 PDT, Timothy Nikkel (:tnikkel)
no flags Details | Diff | Splinter Review
Part 1. Make the immediate discard when untracking an image on nsDocument optional. (8.04 KB, patch)
2012-08-24 12:34 PDT, Timothy Nikkel (:tnikkel)
khuey: review+
bajaj.bhavana: approval‑mozilla‑aurora+
Details | Diff | Splinter Review
Part 2. Don't track images that don't have a frame created. (7.74 KB, patch)
2012-08-24 12:36 PDT, Timothy Nikkel (:tnikkel)
no flags Details | Diff | Splinter Review
Part 1.5. Remove the SHOULD_BE_TRACKED bit. (5.93 KB, patch)
2013-01-08 00:58 PST, Timothy Nikkel (:tnikkel)
khuey: review+
joe: review+
lukasblakk+bugs: approval‑mozilla‑beta-
Details | Diff | Splinter Review
Part 2. Don't track images that don't have a frame created. (6.86 KB, patch)
2013-01-08 01:01 PST, Timothy Nikkel (:tnikkel)
no flags Details | Diff | Splinter Review
Part 2. Don't track images that don't have a frame created. (7.20 KB, patch)
2013-01-17 00:16 PST, Timothy Nikkel (:tnikkel)
justin.lebar+bug: review+
lukasblakk+bugs: approval‑mozilla‑beta-
Details | Diff | Splinter Review
Fix ownerdiscard test. (1.78 KB, patch)
2013-02-05 10:09 PST, Timothy Nikkel (:tnikkel)
josh: review+
Details | Diff | Splinter Review
disable ownerdiscard on crashtest-ipc (705 bytes, patch)
2013-02-06 10:14 PST, Timothy Nikkel (:tnikkel)
josh: review+
Details | Diff | Splinter Review
if we don't decode the image just move on (781 bytes, patch)
2013-02-12 16:05 PST, Timothy Nikkel (:tnikkel)
josh: review+
lukasblakk+bugs: approval‑mozilla‑beta-
Details | Diff | Splinter Review

Description Timothy Nikkel (:tnikkel) 2012-08-21 21:57:40 PDT

    
Comment 1 Timothy Nikkel (:tnikkel) 2012-08-21 21:59:25 PDT
Created attachment 654092 [details] [diff] [review]
part 1
Comment 2 Timothy Nikkel (:tnikkel) 2012-08-21 21:59:43 PDT
Created attachment 654093 [details] [diff] [review]
part 2
Comment 3 Timothy Nikkel (:tnikkel) 2012-08-21 22:00:01 PDT
These cause 1 failure on try server that I still need to solve.
Comment 4 Justin Lebar (not reading bugmail) 2012-08-22 09:09:35 PDT
*** Bug 761113 has been marked as a duplicate of this bug. ***
Comment 5 Timothy Nikkel (:tnikkel) 2012-08-24 12:34:43 PDT
Created attachment 655096 [details] [diff] [review]
Part 1. Make the immediate discard when untracking an image on nsDocument optional.

display: none elements do not get frames created. But frames are also destroyed and quickly recreated if we need to rebuild the frame due to some DOM change that we can't handle any other way. In this case I don't think we want to immediately discard the decoded data. So this adds the ability to do that.
Comment 6 Timothy Nikkel (:tnikkel) 2012-08-24 12:36:08 PDT
Created attachment 655098 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.

Guessing at reviewer here, please redirect if there is a better choice.

This is perhaps a bit complicated. Open to suggestions to streamline.
Comment 7 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-09-19 08:57:19 PDT
Comment on attachment 655096 [details] [diff] [review]
Part 1. Make the immediate discard when untracking an image on nsDocument optional.

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

I think that we want to stop doing RequestDiscard entirely for some of the other pieces of fallout from the last image changes.
Comment 8 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-09-19 09:12:43 PDT
Comment on attachment 655096 [details] [diff] [review]
Part 1. Make the immediate discard when untracking an image on nsDocument optional.

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

Actually, after talking with Justin, we will want the ability to specify whether we discard immediately or not.  We actually will want to backport this to aurora.
Comment 9 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-09-19 09:40:29 PDT
Comment on attachment 655098 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.

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

::: content/base/src/nsImageLoadingContent.cpp
@@ +458,5 @@
> +    if (doc) {
> +      mPendingRequestFlags |= REQUEST_IS_TRACKED;
> +      doc->AddImage(mPendingRequest);
> +    }
> +  }

Why don't you just call TrackImage here?  Why should we ever have a frame but not have REQUEST_SHOULD_BE_TRACKED?

::: content/base/src/nsImageLoadingContent.h
@@ +320,5 @@
>    uint32_t mCurrentRequestFlags;
>    uint32_t mPendingRequestFlags;
>  
>    enum {
>      // Set if the request needs 

While you're here, can you add the missing words here?
Comment 10 Timothy Nikkel (:tnikkel) 2012-10-01 10:15:22 PDT
(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #9)
> ::: content/base/src/nsImageLoadingContent.cpp
> @@ +458,5 @@
> > +    if (doc) {
> > +      mPendingRequestFlags |= REQUEST_IS_TRACKED;
> > +      doc->AddImage(mPendingRequest);
> > +    }
> > +  }
> 
> Why don't you just call TrackImage here?  Why should we ever have a frame
> but not have REQUEST_SHOULD_BE_TRACKED?

Can we get rid of the REQUEST_SHOULD_BE_TRACKED bit and assume that all non-null mCurrent/PendingRequest should be tracked?
Comment 11 Timothy Nikkel (:tnikkel) 2012-10-01 10:54:55 PDT
Pushed part 1
https://hg.mozilla.org/integration/mozilla-inbound/rev/f127f704815c
Comment 12 Timothy Nikkel (:tnikkel) 2012-10-01 10:57:02 PDT
Comment on attachment 655096 [details] [diff] [review]
Part 1. Make the immediate discard when untracking an image on nsDocument optional.

[Approval Request Comment]
Bug caused by (feature/regressing bug #): this patch should have no effect. It adds an option and never uses it (so that future patches can use it). Kyle wants this patch so he can write a fix on top of it for bug 791731.
User impact if declined: none
Testing completed (on m-c, etc.): none
Risk to taking this patch (and alternatives if risky): none
String or UUID changes made by this patch: none
Comment 13 Ryan VanderMeulen [:RyanVM] 2012-10-01 18:59:22 PDT
https://hg.mozilla.org/mozilla-central/rev/f127f704815c
Comment 14 Ryan VanderMeulen [:RyanVM] 2012-10-01 19:05:40 PDT
(In the future, put [leave open] in the whiteboard to avoid auto-resolves like that)
Comment 15 Justin Wood (:Callek) 2012-10-07 21:13:37 PDT
Comment on attachment 655096 [details] [diff] [review]
Part 1. Make the immediate discard when untracking an image on nsDocument optional.

In doing approval-but-not-landed triage:
$ hg qpush
applying discardoptional
patching file content/base/src/nsImageLoadingContent.cpp
Hunk #1 FAILED at 1167
1 out of 2 hunks FAILED -- saving rejects to file content/base/src/nsImageLoadingContent.cpp.rej
patch failed, unable to continue (try -v)
patch failed, rejects left in working dir
errors during apply, please fix and refresh discardoptional

So not pushing (since I don't want to manually unwrap patch rejects right now)
Comment 16 Justin Lebar (not reading bugmail) 2012-10-07 23:15:18 PDT
> $ hg transplant -s ~/code/moz/ff-clean/src f127f704815c

Worked fine for me.

Pushed part 1 to Aurora (needed for bug 791731): https://hg.mozilla.org/releases/mozilla-aurora/rev/c0a393d6210a
Comment 17 Timothy Nikkel (:tnikkel) 2012-11-08 20:30:28 PST
Kyle, did you see comment 10?
Comment 18 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-12-07 15:44:39 PST
(In reply to Timothy Nikkel (:tn) from comment #10)
> (In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #9)
> > ::: content/base/src/nsImageLoadingContent.cpp
> > @@ +458,5 @@
> > > +    if (doc) {
> > > +      mPendingRequestFlags |= REQUEST_IS_TRACKED;
> > > +      doc->AddImage(mPendingRequest);
> > > +    }
> > > +  }
> > 
> > Why don't you just call TrackImage here?  Why should we ever have a frame
> > but not have REQUEST_SHOULD_BE_TRACKED?
> 
> Can we get rid of the REQUEST_SHOULD_BE_TRACKED bit and assume that all
> non-null mCurrent/PendingRequest should be tracked?

I believe we can.  The everytime we call PrepareNextRequest and store something into it we then track the request.
Comment 19 Timothy Nikkel (:tnikkel) 2013-01-08 00:57:03 PST
(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #9)
> ::: content/base/src/nsImageLoadingContent.cpp
> @@ +458,5 @@
> > +    if (doc) {
> > +      mPendingRequestFlags |= REQUEST_IS_TRACKED;
> > +      doc->AddImage(mPendingRequest);
> > +    }
> > +  }
> 
> Why don't you just call TrackImage here?  Why should we ever have a frame
> but not have REQUEST_SHOULD_BE_TRACKED?

We actually can't call TrackImage from FrameCreated because the primary frame pointer on the content node hasn't been setup when FrameCreated is called so there isn't a way for TrackImage to tell that we have a frame.
Comment 20 Timothy Nikkel (:tnikkel) 2013-01-08 00:58:10 PST
Created attachment 699037 [details] [diff] [review]
Part 1.5. Remove the SHOULD_BE_TRACKED bit.
Comment 21 Timothy Nikkel (:tnikkel) 2013-01-08 00:59:10 PST
Comment on attachment 699037 [details] [diff] [review]
Part 1.5. Remove the SHOULD_BE_TRACKED bit.

I think Kyle might be busy, trying another reviewer, not sure if good choice.
Comment 22 Timothy Nikkel (:tnikkel) 2013-01-08 01:01:47 PST
Created attachment 699039 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.

Rebased on top of part 1.5.
Comment 23 Joe Drew (not getting mail) 2013-01-08 09:36:41 PST
Comment on attachment 699039 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.

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

This is all sort of over my head. Maybe jlebar?
Comment 24 Justin Lebar (not reading bugmail) 2013-01-08 09:42:19 PST
Comment on attachment 699039 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.

I think I can look at this, but are you OK waiting a few days?  I'm at the B2G work week.
Comment 25 Timothy Nikkel (:tnikkel) 2013-01-08 11:54:35 PST
Sure, a few days is better than 3 months. Alternatively I'm not sure who are all good reviewers here, so feel free to suggest another.
Comment 26 Justin Lebar (not reading bugmail) 2013-01-16 14:42:51 PST
Comment on attachment 699039 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.

Sorry for making you wait so long on this one; thanks for being patient.

Can mPendingRequest == mCurrentRequest?  It's not totally clear to me from the existing code, but perhaps we should at least assert not, because you assume not in TrackImage.  Or if you're not confident in that assumption, let's just make the code work in both cases.

What if we encapsulated this better?  e.g.

  EnsureRequestIsTrackedInDoc(imgIRequest* aRequest, nsIDocument* aDocument)
  {
    MOZ_ASSERT(!aRequest || aRequest == mCurrentRequest || aRequest == mPendingRequest);

    if (!aRequest) {
      return;
    }

    if (aRequest == mCurrentRequest && !(mCurrentRequestFlags & REQUEST_IS_TRACKED)) {
      mCurrentRequestFlags |= REQUEST_IS_TRACKED;
      aDocument->AddImage(mCurrentRequest);
    }

    if (aRequest == mPendingRequest && !(mPendingRequestFlags & REQUEST_IS_TRACKED)) {
      ...
    }
  }

  EnsureRequestNotTrackedInDoc(...) { ... }

Or, if those method names are too similar to each other, here are some
alternatives:

  TrackRequestInDoc / UntrackRequestInDoc, or
  AddRequestToDoc / RemoveRequestFromDoc
  Either of the two above with "Maybe" added on. 

I'm not totally satisfied with any of these names, but the encapsulation feels
much less error-prone to me.  What do you think?
Comment 27 Timothy Nikkel (:tnikkel) 2013-01-16 16:42:50 PST
(In reply to Justin Lebar [:jlebar] from comment #26)
> Can mPendingRequest == mCurrentRequest?  It's not totally clear to me from
> the existing code, but perhaps we should at least assert not, because you
> assume not in TrackImage.  Or if you're not confident in that assumption,
> let's just make the code work in both cases.

Part 1.5 removes code that has been there for a while that makes the same assumption. But I'm not sure if mPendingRequest == mCurrentRequest is valid or not so I'll make a change like you suggest.
Comment 28 Timothy Nikkel (:tnikkel) 2013-01-17 00:16:26 PST
Created attachment 703194 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.
Comment 30 Phil Ringnalda (:philor) 2013-01-18 20:12:12 PST
Backed out in https://hg.mozilla.org/integration/mozilla-inbound/rev/31fea3e0be16 - Android crashtest-3 said, entirely too often, "ownerdiscard.html | load failed: timed out waiting for reftest-wait to be removed." I gathered up links to the logs that failed in a neat little bundle for you in bug 832571.
Comment 31 Timothy Nikkel (:tnikkel) 2013-02-05 10:09:40 PST
Created attachment 710271 [details] [diff] [review]
Fix ownerdiscard test.

So it appears the goal of this test is to hit imgRequestProxy::ChangeOwner with mCanceled == true on the img element in the child iframe and then discard that image. This is how that happens.

When the img element gets parsed and added to the tree it will call HTMLImageElement::MaybePreloadImage which will load the image and create a nsInputStreamReadyEvent.

The img element and the iframe containing the other img element are removed from the document via the adoptNode call. This calls Cancel on the imgRequestProxy and sets mCanceled to true.

The nsInputStreamReadyEvent now runs which eventually calls imgRequestProxy::ChangeOwner.

So since it is the img element in the child iframe which is important, waiting for DOMContentLoaded on the parent document isn't good enough, the img element in the child iframe may not have been created yet. So instead wait for DOMContentLoaded on the child iframe to remove the nodes from the document. This seems to test the same condition.

This also seems to make us get the same blockonload assertion more, probably cause we get it for both img elements.
Comment 32 Josh Matthews [:jdm] (on vacation until Dec 5) 2013-02-06 03:29:04 PST
Comment on attachment 710271 [details] [diff] [review]
Fix ownerdiscard test.

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

Good detective work. Sorry for making you do it!
Comment 33 Timothy Nikkel (:tnikkel) 2013-02-06 10:14:41 PST
Created attachment 710810 [details] [diff] [review]
disable ownerdiscard on crashtest-ipc

So the fixed test plus the patches from this bug make the test go orange on linux crashtest-ipc some of the time (some pushes seem unaffected, other are not). I've have put in significant effort into reproducing this locally, trying different configurations on three different machines, but so far I have failed to reproduce locally. try is very backed up this whole week on linux32 test jobs. You basically get one result per 24 hours, or two if you are lucky. Making figuring this out via try server much more difficult than usual.

So given that the test is buggy (nothing in the test requires us to ever decode an image) I would like to disable the test on crashtest-ipc so I can unblock on landing these patches while I continue to slowly debug this test via tryserver.
Comment 34 Timothy Nikkel (:tnikkel) 2013-02-06 17:26:39 PST
https://hg.mozilla.org/integration/mozilla-inbound/rev/d2fda338874d
Comment 36 Timothy Nikkel (:tnikkel) 2013-02-12 16:05:50 PST
Created attachment 713164 [details] [diff] [review]
if we don't decode the image just move on

So before the patches of this bug a full decode of the image could be kicked off either in nsImageLoadingContent::BindToTree when the image was bound to the tree, or through the following sequence:
-HTMLImageElement::MaybeLoadImage is called when the image element is added to the tree. It starts loading the image by creating a network request for it.
-when this network request actually starts getting data we create a RasterImage
-the loading of the image via MaybeLoadImage also calls imgStatusTracker::Notify, which creates a runnable that calls SyncNotify when it runs.
-when SyncNotify is called if the imgStatusTracker has an mImage it calls FrameRect on that image, which asks for a full decode via GetCurrentImgFrame, GetImgFrame, WantDecodedFrames, StartDecoding.
So you can see that if the network request gets data available after the runnable calls imgStatusTracker::SyncNotify we won't have an mImage in SyncNotify.

If our goal is to have an image discarded that has had ChangeOwner called on it's proxy when that proxy had mCanceled == true I think the test is currently do that the best way possible, unless we add some new notifications. The test as it is written has no guarantee that the image will ever be decoded (it's removed before it is ever displayed). And I don't know of a way to force that and maintain the property that we call ChangeOwner on a canceled proxy, because ChangeOwner happens fairly early in the loading of the image, and decoding happens comparatively later.

So given that most of the time we are testing the correct thing by the test, and some of the time don't test anything I think it's reasonable to just move on past the test if the image wasn't decoded.
Comment 39 Timothy Nikkel (:tnikkel) 2013-03-08 12:26:06 PST
Comment on attachment 703194 [details] [diff] [review]
Part 2. Don't track images that don't have a frame created.

We want these to fix bug 843213, which was caused by bug 791571.
[Approval Request Comment]
Bug caused by (feature/regressing bug #): bug 791571 caused bug 843213
User impact if declined: image doesn't show up in some situations. I haven't debugged the problematic page so I'm not sure exactly what the situation is.
Testing completed (on m-c, etc.): three or more weeks on m-c and now on aurora
Risk to taking this patch (and alternatives if risky): there is a small amount of risk with these patches. An alternative would be to invest more time into debugging the problem and fixing it differently; fixing bug 843213 was not a known or sought outcome of landing these patches.
String or UUID changes made by this patch: none
Comment 40 Timothy Nikkel (:tnikkel) 2013-03-08 12:26:41 PST
Comment on attachment 699037 [details] [diff] [review]
Part 1.5. Remove the SHOULD_BE_TRACKED bit.

[Approval Request Comment]
See comment 39.
Comment 41 Timothy Nikkel (:tnikkel) 2013-03-08 12:26:59 PST
Comment on attachment 713164 [details] [diff] [review]
if we don't decode the image just move on

[Approval Request Comment]
See comment 39.
Comment 42 Lukas Blakk [:lsblakk] use ?needinfo 2013-03-08 14:43:47 PST
Timothy, bug 843213 has not landed on FF20 (Beta) - are you intending this for mozilla-aurora approval?
Comment 43 Timothy Nikkel (:tnikkel) 2013-03-08 14:47:57 PST
(In reply to Lukas Blakk [:lsblakk] from comment #42)
> Timothy, bug 843213 has not landed on FF20 (Beta) - are you intending this
> for mozilla-aurora approval?

Bug 843213 has no patches, it hasn't landed anywhere. This bug (bug 784591) fixes bug 843213. Bug 843213 was caused by bug 791571.

The patches on this bug are already on aurora.
Comment 44 Lukas Blakk [:lsblakk] use ?needinfo 2013-03-11 09:53:47 PDT
Comment on attachment 699037 [details] [diff] [review]
Part 1.5. Remove the SHOULD_BE_TRACKED bit.

Thanks for the clarification - but looking closer I think that as mentioned in bug 843213 comment 7 - this regression has been around since 17 and since we have the fix in Aurora it can ride the trains from there so we're not taking unecessary risk in Beta at this point.

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