Bug 104734 - [V8] Reachable event listeners on image elements can be collected in a minor DOM GC
Summary: [V8] Reachable event listeners on image elements can be collected in a minor ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kentaro Hara
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-11 15:55 PST by Kentaro Hara
Modified: 2012-12-11 21:59 PST (History)
6 users (show)

See Also:


Attachments
Patch (2.65 KB, patch)
2012-12-11 16:07 PST, Kentaro Hara
no flags Details | Formatted Diff | Diff
patch for landing (3.61 KB, patch)
2012-12-11 16:38 PST, Kentaro Hara
no flags Details | Formatted Diff | Diff
Patch (3.18 KB, patch)
2012-12-11 18:00 PST, Kentaro Hara
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kentaro Hara 2012-12-11 15:55:05 PST
Chromium bug: http://code.google.com/p/chromium/issues/detail?id=164882
Comment 1 Kentaro Hara 2012-12-11 16:07:09 PST
Created attachment 178908 [details]
Patch
Comment 2 Kenneth Russell 2012-12-11 16:18:13 PST
Comment on attachment 178908 [details]
Patch

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

The code change looks OK as an immediate patch. Please make the comments more precise. I am concerned that this is only one example of a pattern where a DOM related object has a JavaScript callback, and that the new minor DOM GC may be collecting the JavaScript wrappers for those objects too eagerly, causing callbacks to randomly not be called. I'm concerned about XMLHttpRequest in particular. I think the V8 team and all reviewers of the minor DOM GC algorithm should be engaged urgently to discuss what is going on here. r=me

> Source/WebCore/ChangeLog:16
> +        However, as far as I experimented, it looks like this patch fixes the bug.

Is the test case tf-test.zip attached to https://code.google.com/p/chromium/issues/detail?id=164882 sufficient?

> Source/WebCore/bindings/v8/V8GCController.cpp:226
> +            // FIXME: I'm not sure why node->hasEventListeners() is needed.

It seems to me that the JavaScript wrapper for the Image element is being garbage collected too early. I think it is worth mentioning this in the comment.

> Source/WebCore/bindings/v8/V8GCController.cpp:227
> +            // But without this check, image loading can crash.

It isn't that image loading can crash; it is that the image's onload handler is never called.
Comment 3 Kentaro Hara 2012-12-11 16:38:23 PST
Created attachment 178916 [details]
patch for landing
Comment 4 Kentaro Hara 2012-12-11 16:47:32 PST
(In reply to comment #2)
> (From update of attachment 178908 [details])
> 
> > Source/WebCore/bindings/v8/V8GCController.cpp:226
> > +            // FIXME: I'm not sure why node->hasEventListeners() is needed.
> 
> It seems to me that the JavaScript wrapper for the Image element is being garbage collected too early. I think it is worth mentioning this in the comment.

Improved the comment. Thanks!

> > Source/WebCore/bindings/v8/V8GCController.cpp:227
> > +            // But without this check, image loading can crash.
> 
> It isn't that image loading can crash; it is that the image's onload handler is never called.

Fixed.

> I am concerned that this is only one example of a pattern where a DOM related object has a JavaScript callback, and that the new minor DOM GC may be collecting the JavaScript wrappers for those objects too eagerly, causing callbacks to randomly not be called. I'm concerned about XMLHttpRequest in particular. I think the V8 team and all reviewers of the minor DOM GC algorithm should be engaged urgently to discuss what is going on here. r=me

Will investigate. Although XMLHttpRequest is not a problem because it is not a DOM node (XMLHttpRequest is a DOM object and thus the minor GC does nothing), the problem can happen for audio elements and video elements that have some pending activities.
Comment 5 Kentaro Hara 2012-12-11 18:00:11 PST
Created attachment 178937 [details]
Patch
Comment 6 Kenneth Russell 2012-12-11 18:02:20 PST
Comment on attachment 178937 [details]
Patch

Looks good -- but is it not possible to add a test for this? Something along the lines of loading a bunch of images and ensuring that their onload handlers are all eventually called. r=me
Comment 7 Kentaro Hara 2012-12-11 18:07:18 PST
Comment on attachment 178937 [details]
Patch

For now let me land the patch, since this is an urgent fix and this change is anyway harmless. Let me seek a good way to test the change.
Comment 8 Kenneth Russell 2012-12-11 18:23:44 PST
(In reply to comment #7)
> (From update of attachment 178937 [details])
> For now let me land the patch, since this is an urgent fix and this change is anyway harmless. Let me seek a good way to test the change.

Agree.
Comment 9 WebKit Review Bot 2012-12-11 21:59:46 PST
Comment on attachment 178937 [details]
Patch

Clearing flags on attachment: 178937

Committed r137415: <http://trac.webkit.org/changeset/137415>
Comment 10 WebKit Review Bot 2012-12-11 21:59:49 PST
All reviewed patches have been landed.  Closing bug.