<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>43423</bug_id>
          
          <creation_ts>2010-08-03 08:43:24 -0700</creation_ts>
          <short_desc>HTML5 parser may cause onload not to fire</short_desc>
          <delta_ts>2010-08-04 02:31:58 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>41115</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Ben Murdoch">benm</reporter>
          <assigned_to name="Ben Murdoch">benm</assigned_to>
          <cc>abarth</cc>
    
    <cc>eric</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>259481</commentid>
    <comment_count>0</comment_count>
    <who name="Ben Murdoch">benm</who>
    <bug_when>2010-08-03 08:43:24 -0700</bug_when>
    <thetext>If a sufficiently complex page causes the HTML5 parser to yield (i.e. &gt; 4096 tokens and &gt; 0.5 parsing time), when we return to parsing and complete the document, onload is not fired.

Patch to follow.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259596</commentid>
    <comment_count>1</comment_count>
    <who name="Ben Murdoch">benm</who>
    <bug_when>2010-08-03 11:48:51 -0700</bug_when>
    <thetext>Attaching the code change that I propose to fix the bug.

I haven&apos;t set r? yet or created a ChangeLog as I&apos;ve been trying to write a layout test for this. It&apos;s tricky as we need to make the parser stall (without creating a new PumpSession) so that it triggers the timeout on HTMLParserScheduler.h:59, i.e. elapsedTime needs to be greater than 0.5 seconds. Thanks to Adam&apos;s advice on trying to write a PHP script that sleeps/flushes, I managed to write a layout test that works on Windows, but natch when moving it to my Mac to try it doesn&apos;t trigger the bug. I fear this is going to be very tricky to reliably test due to the timing based nature of what we are testing. If for example the parser speeds up due to a hardware change we might not trigger the timeout anymore and this test would become useless.

Any ideas folks? I can attach the layout test that worked on Windows if it might help.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259597</commentid>
    <comment_count>2</comment_count>
      <attachid>63362</attachid>
    <who name="Ben Murdoch">benm</who>
    <bug_when>2010-08-03 11:50:37 -0700</bug_when>
    <thetext>Created attachment 63362
Fix and potential layout test ideas

The Windows layout test is actually attached to the patch as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259607</commentid>
    <comment_count>3</comment_count>
      <attachid>63362</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2010-08-03 12:04:48 -0700</bug_when>
    <thetext>Comment on attachment 63362
Fix and potential layout test ideas

You may be fighting the layout timer.

The two constants you&apos;re trying to trip in your test are:

// defaultParserChunkSize is used to define how many tokens the parser will
// process before checking against parserTimeLimit and possibly yielding.
// This is a performance optimization to prevent checking after every token.
static const int defaultParserChunkSize = 4096;

// defaultParserTimeLimit is the seconds the parser will run in one write() call
// before yielding.  Inline &lt;script&gt; execution can cause it to excede the limit.
// FIXME: We would like this value to be 0.2.
static const double defaultParserTimeLimit = 0.500;

Why do you ahve this section:
+&lt;!--
+&lt;?php
+print str_repeat(&quot;A&quot;, 2048);
+?&gt;
+--&gt;

To get around some buffering delay at the network layer?

What do you mean by &quot;start a new PumpSession&quot;?

Isn&apos;t the parser in full control until it yields (by being blocked by a script).

I guess you have to be careful that the final pumping will be done inside resumeParsingAfterYield, so you need to send more than 4096 tokens, but fewer than 8192, right?

Ideally you&apos;d want the tokens as small as possible.

You might try sending &lt;a&gt;&lt;/a&gt; instead (two tokens).  You could send &lt;a&gt;a&lt;/a&gt;a to get 4 tokens per bunch instead.

Of course you have to send the 4096th token after 0.5 seconds to hav it yield.  And then you need to have sent all of the rest of the document before it ends up resuming from its yield.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259608</commentid>
    <comment_count>4</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2010-08-03 12:05:11 -0700</bug_when>
    <thetext>I agree, this is complicated to test and may not be reliably testable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259609</commentid>
    <comment_count>5</comment_count>
    <who name="Ben Murdoch">benm</who>
    <bug_when>2010-08-03 12:09:17 -0700</bug_when>
    <thetext>(In reply to comment #3)

Thanks for the ideas Eric!

&gt; Why do you ahve this section:
&gt; +&lt;!--
&gt; +&lt;?php
&gt; +print str_repeat(&quot;A&quot;, 2048);
&gt; +?&gt;
&gt; +--&gt;
&gt; 
&gt; To get around some buffering delay at the network layer?

Exactly.

&gt; 
&gt; What do you mean by &quot;start a new PumpSession&quot;?

Well, it seemed to me that the startTime that we compare with when we decide to yield or not is set in the PumpSession constructor. I&apos;m not exactly sure what constitutes a PumpSession though?

&gt;
&gt; Isn&apos;t the parser in full control until it yields (by being blocked by a script).
&gt; 
&gt; I guess you have to be careful that the final pumping will be done inside resumeParsingAfterYield, so you need to send more than 4096 tokens, but fewer than 8192, right?
&gt; 
&gt; Ideally you&apos;d want the tokens as small as possible.
&gt; 
&gt; You might try sending &lt;a&gt;&lt;/a&gt; instead (two tokens).  You could send &lt;a&gt;a&lt;/a&gt;a to get 4 tokens per bunch instead.
&gt; 
&gt; Of course you have to send the 4096th token after 0.5 seconds to hav it yield.  And then you need to have sent all of the rest of the document before it ends up resuming from its yield.

Good suggestions, I&apos;ll give it a shot.

Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259634</commentid>
    <comment_count>6</comment_count>
    <who name="Ben Murdoch">benm</who>
    <bug_when>2010-08-03 12:46:08 -0700</bug_when>
    <thetext>Still no luck.

I think the problem is that as soon as the pump loop in HTMLDocumentParser doesn&apos;t see a token, we stop pumping (and also presumably then the PumpingSession?). Trying to stall by sleeping in the php script causes the tokenizer to not get a token, so we break out of the loop and so when the PHP resumes, we need to send another 4096 tokens, etc...

Test aside, does this look like a sane fix?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259641</commentid>
    <comment_count>7</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2010-08-03 12:55:53 -0700</bug_when>
    <thetext>The fix looks great.

I think you should upload a patch which explains that this seems impossible to test.

And then I&apos;ll happily r+ it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259656</commentid>
    <comment_count>8</comment_count>
      <attachid>63371</attachid>
    <who name="Ben Murdoch">benm</who>
    <bug_when>2010-08-03 13:14:54 -0700</bug_when>
    <thetext>Created attachment 63371
Patch.

Awesome, thanks Eric!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259664</commentid>
    <comment_count>9</comment_count>
      <attachid>63371</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2010-08-03 13:26:31 -0700</bug_when>
    <thetext>Comment on attachment 63371
Patch.

Typo: &quot;dependant&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>259937</commentid>
    <comment_count>10</comment_count>
    <who name="Ben Murdoch">benm</who>
    <bug_when>2010-08-04 02:31:58 -0700</bug_when>
    <thetext>Fixed Changelog typo.

Sending        WebCore/ChangeLog
Sending        WebCore/html/HTMLDocumentParser.cpp
Transmitting file data ..
Committed revision 64638.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>63362</attachid>
            <date>2010-08-03 11:50:37 -0700</date>
            <delta_ts>2010-08-03 13:14:54 -0700</delta_ts>
            <desc>Fix and potential layout test ideas</desc>
            <filename>patch-1.txt</filename>
            <type>text/plain</type>
            <size>1680</size>
            <attacher name="Ben Murdoch">benm</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvaHRtbC9IVE1MRG9jdW1lbnRQYXJzZXIuY3BwCj09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0t
IFdlYkNvcmUvaHRtbC9IVE1MRG9jdW1lbnRQYXJzZXIuY3BwCShyZXZpc2lvbiA2NDM1NSkKKysr
IFdlYkNvcmUvaHRtbC9IVE1MRG9jdW1lbnRQYXJzZXIuY3BwCSh3b3JraW5nIGNvcHkpCkBAIC0x
MzgsNiArMTM4LDcgQEAgdm9pZCBIVE1MRG9jdW1lbnRQYXJzZXI6OnJlc3VtZVBhcnNpbmdBZgog
ICAgIC8vIFdlIHNob3VsZCBuZXZlciBiZSBoZXJlIHVubGVzcyB3ZSBjYW4gcHVtcCBpbW1lZGlh
dGVseS4gIENhbGwgcHVtcFRva2VuaXplcigpCiAgICAgLy8gZGlyZWN0bHkgc28gdGhhdCBBU1NF
UlRTIHdpbGwgZmlyZSBpZiB3ZSdyZSB3cm9uZy4KICAgICBwdW1wVG9rZW5pemVyKEFsbG93WWll
bGQpOworICAgIGVuZElmRGVsYXllZCgpOwogfQogCiBib29sIEhUTUxEb2N1bWVudFBhcnNlcjo6
cnVuU2NyaXB0c0ZvclBhdXNlZFRyZWVCdWlsZGVyKCkKSW5kZXg6IExheW91dFRlc3RzL2h0dHAv
dGVzdHMvbG9hZGluZy9vbmxvYWQtZmlyZXMtYWZ0ZXItcGFyc2VyLXlpZWxkcy5waHAKPT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PQotLS0gTGF5b3V0VGVzdHMvaHR0cC90ZXN0cy9sb2FkaW5nL29ubG9hZC1maXJlcy1hZnRl
ci1wYXJzZXIteWllbGRzLnBocAkocmV2aXNpb24gMCkKKysrIExheW91dFRlc3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WVsZHMucGhwCl9fX19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KQWRk
ZWQ6IHN2bjpleGVjdXRhYmxlCiAgICsgKgoK
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>63371</attachid>
            <date>2010-08-03 13:14:54 -0700</date>
            <delta_ts>2010-08-03 13:26:31 -0700</delta_ts>
            <desc>Patch.</desc>
            <filename>43423.txt</filename>
            <type>text/plain</type>
            <size>1841</size>
            <attacher name="Ben Murdoch">benm</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiA2NDU4MykKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMjcgQEAKKzIwMTAtMDgtMDMgIEJlbiBNdXJkb2NoICA8YmVubUBnb29nbGUuY29t
PgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgIEhUTUw1
IHBhcnNlciBtYXkgY2F1c2Ugb25sb2FkIG5vdCB0byBmaXJlCisgICAgICAgIGh0dHBzOi8vYnVn
cy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD00MzQyMworCisgICAgICAgIElmIGEgY29tcGxl
eCBwYWdlIGNhdXNlcyB0aGUgSFRNTCBwYXJzZXIgdG8geWllbGQsCisgICAgICAgIHRoZW4gd2hl
biBwYXJzaW5nIGNvbnRpbnVlcyBhZ2FpbiBhbmQgZXZlbnR1YWxseQorICAgICAgICBmaW5pc2hl
cywgd2UgYXJlIG1pc3NpbmcgYSBjYWxsIHRvIGVuZElmRGVsYXllZCgpLiBUaGlzCisgIC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PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvaHRtbC9I
VE1MRG9jdW1lbnRQYXJzZXIuY3BwCShyZXZpc2lvbiA2NDM1NSkKKysrIFdlYkNvcmUvaHRtbC9I
VE1MRG9jdW1lbnRQYXJzZXIuY3BwCSh3b3JraW5nIGNvcHkpCkBAIC0xMzgsNiArMTM4LDcgQEAg
dm9pZCBIVE1MRG9jdW1lbnRQYXJzZXI6OnJlc3VtZVBhcnNpbmdBZgogICAgIC8vIFdlIHNob3Vs
ZCBuZXZlciBiZSBoZXJlIHVubGVzcyB3ZSBjYW4gcHVtcCBpbW1lZGlhdGVseS4gIENhbGwgcHVt
cFRva2VuaXplcigpCiAgICAgLy8gZGlyZWN0bHkgc28gdGhhdCBBU1NFUlRTIHdpbGwgZmlyZSBp
ZiB3ZSdyZSB3cm9uZy4KICAgICBwdW1wVG9rZW5pemVyKEFsbG93WWllbGQpOworICAgIGVuZElm
RGVsYXllZCgpOwogfQogCiBib29sIEhUTUxEb2N1bWVudFBhcnNlcjo6cnVuU2NyaXB0c0ZvclBh
dXNlZFRyZWVCdWlsZGVyKCk=
</data>
<flag name="review"
          id="51714"
          type_id="1"
          status="+"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>