Bug 110388 - Preloads should be cleared when JavaScript cancels loading prematurely.
Summary: Preloads should be cleared when JavaScript cancels loading prematurely.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: James Simonsen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-20 14:54 PST by James Simonsen
Modified: 2013-02-22 14:02 PST (History)
9 users (show)

See Also:


Attachments
Patch (4.94 KB, patch)
2013-02-20 14:55 PST, James Simonsen
no flags Details | Formatted Diff | Diff
Patch (5.09 KB, patch)
2013-02-20 17:16 PST, James Simonsen
no flags Details | Formatted Diff | Diff
Patch (5.10 KB, patch)
2013-02-21 11:51 PST, James Simonsen
no flags Details | Formatted Diff | Diff
Patch (5.18 KB, patch)
2013-02-21 11:59 PST, James Simonsen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Simonsen 2013-02-20 14:54:10 PST
Preloads should be cleared on document.write()
Comment 1 James Simonsen 2013-02-20 14:55:34 PST
Created attachment 189386 [details]
Patch
Comment 2 James Simonsen 2013-02-20 14:57:04 PST
This was discovered and reported internally at Google. Preloaded resources were being reused after a document.write() even though they were explicitly marked no-cache.
Comment 3 Adam Barth 2013-02-20 14:58:18 PST
Comment on attachment 189386 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=189386&action=review

> Source/WebCore/dom/Document.cpp:4407
> +    // Parser should have picked up all preloads by now
> +    m_cachedResourceLoader->clearPreloads();

This isn't true for the threaded parser.  The threaded parser doesn't finish synchronously.
Comment 4 James Simonsen 2013-02-20 14:59:40 PST
(In reply to comment #3)
> (From update of attachment 189386 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=189386&action=review
> 
> > Source/WebCore/dom/Document.cpp:4407
> > +    // Parser should have picked up all preloads by now
> > +    m_cachedResourceLoader->clearPreloads();
> 
> This isn't true for the threaded parser.  The threaded parser doesn't finish synchronously.

It calls finishedParsing() before it's actually finished?
Comment 5 WebKit Review Bot 2013-02-20 15:37:24 PST
Comment on attachment 189386 [details]
Patch

Attachment 189386 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/16660547

New failing tests:
fast/js/regress/inlined-put-by-id-transition.html
Comment 6 James Simonsen 2013-02-20 15:41:38 PST
(In reply to comment #5)
> (From update of attachment 189386 [details])
> Attachment 189386 [details] did not pass chromium-ews (chromium-xvfb):
> Output: http://queues.webkit.org/results/16660547
> 
> New failing tests:
> fast/js/regress/inlined-put-by-id-transition.html

This appears to be a flake. It doesn't reproduce locally and seems totally unrelated.
Comment 7 Antti Koivisto 2013-02-20 17:10:35 PST
Comment on attachment 189386 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=189386&action=review

> Source/WebCore/ChangeLog:9
> +
> +        We should clear preloads as soon as the parser finishes, instead of waiting for
> +        implicitClose(), which doesn't happen with a document.write().

Why? Please describe the problem you are fixing in the ChangeLog.
Comment 8 Antti Koivisto 2013-02-20 17:11:02 PST
(In reply to comment #2)
> This was discovered and reported internally at Google. Preloaded resources were being reused after a document.write() even though they were explicitly marked no-cache.

What makes you think this is a bug?
Comment 9 James Simonsen 2013-02-20 17:16:33 PST
Created attachment 189421 [details]
Patch
Comment 10 James Simonsen 2013-02-20 17:16:56 PST
(In reply to comment #7)
> (From update of attachment 189386 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=189386&action=review
> 
> > Source/WebCore/ChangeLog:9
> > +
> > +        We should clear preloads as soon as the parser finishes, instead of waiting for
> > +        implicitClose(), which doesn't happen with a document.write().
> 
> Why? Please describe the problem you are fixing in the ChangeLog.

Done.
Comment 11 Adam Barth 2013-02-20 19:48:23 PST
> It calls finishedParsing() before it's actually finished?

Nope.  You're right!  I was confused with finishParsing.  :)
Comment 12 Antti Koivisto 2013-02-21 09:32:33 PST
Comment on attachment 189421 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=189421&action=review

> Source/WebCore/ChangeLog:11
> +        Preloads should be cleared on document.write()
> +        https://bugs.webkit.org/show_bug.cgi?id=110388
> +
> +        Reviewed by NOBODY (OOPS!).
> +
> +        If a page preloads a resource, then uses document.write(), that resource is forever marked
> +        as a preload and will always be fetched from cache even after an explicit reload. Instead,
> +        we should clear the preloads as soon as the parser finishes, rather than waiting for
> +        implicitClose.

I still don't quite understand. What does document.write have to do with this? Your test case does not use document.write.
Comment 13 James Simonsen 2013-02-21 11:51:03 PST
Created attachment 189568 [details]
Patch
Comment 14 James Simonsen 2013-02-21 11:55:47 PST
(In reply to comment #12)
> (From update of attachment 189421 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=189421&action=review
> 
> > Source/WebCore/ChangeLog:11
> > +        Preloads should be cleared on document.write()
> > +        https://bugs.webkit.org/show_bug.cgi?id=110388
> > +
> > +        Reviewed by NOBODY (OOPS!).
> > +
> > +        If a page preloads a resource, then uses document.write(), that resource is forever marked
> > +        as a preload and will always be fetched from cache even after an explicit reload. Instead,
> > +        we should clear the preloads as soon as the parser finishes, rather than waiting for
> > +        implicitClose.
> 
> I still don't quite understand. What does document.write have to do with this? Your test case does not use document.write.

Oh. Good point. I must've inadvertently removed that while I was working on it.  It seems both cases cause problems though, so I've updated the description to match.

Basically (if it's not clear already), the problem is that some resources get permanently marked as preloads. When you reload the page, we reuse the resource from memory cache because it's still marked as as preload even though the resource is explicitly no-cache. So, we need to more aggressively clear out the preloads when JavaScript stops the parser.
Comment 15 James Simonsen 2013-02-21 11:59:23 PST
Created attachment 189569 [details]
Patch
Comment 16 Adam Barth 2013-02-21 17:16:13 PST
Antti, did you have further comments on this patch?
Comment 17 Antti Koivisto 2013-02-22 07:15:08 PST
Comment on attachment 189569 [details]
Patch

Ok, r=me
Comment 18 WebKit Review Bot 2013-02-22 14:01:56 PST
Comment on attachment 189569 [details]
Patch

Clearing flags on attachment: 189569

Committed r143789: <http://trac.webkit.org/changeset/143789>
Comment 19 WebKit Review Bot 2013-02-22 14:02:02 PST
All reviewed patches have been landed.  Closing bug.