<?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>49935</bug_id>
          
          <creation_ts>2010-11-22 13:41:04 -0800</creation_ts>
          <short_desc>Crash at WebCore::ScriptElementData::execute (AsyncScriptRunner&apos;s timer fires after the document is unloaded)</short_desc>
          <delta_ts>2011-01-21 10:26:57 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>HasReduction, InRadar</keywords>
          <priority>P1</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ryosuke Niwa">rniwa</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>abarth</cc>
    
    <cc>ap</cc>
    
    <cc>koivisto</cc>
    
    <cc>mitz</cc>
    
    <cc>sam</cc>
    
    <cc>tonyg</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>312488</commentid>
    <comment_count>0</comment_count>
      <attachid>74591</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2010-11-22 13:41:04 -0800</bug_when>
    <thetext>Created attachment 74591
demo

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb1e5ab70 (LWP 9849)]
WebCore::ScriptElementData::execute (this=0x35c62f4, cachedScript=0x0) at third_party/WebKit/WebCore/dom/ScriptElement.cpp:219
219         if (cachedScript-&gt;errorOccurred())

#0  WebCore::ScriptElementData::execute (this=0x35c62f4, cachedScript=0x0) at third_party/WebKit/WebCore/dom/ScriptElement.cpp:219
#1  0x019e1d04 in WebCore::AsyncScriptRunner::timerFired (this=0x3588740, timer=0x3588750) at third_party/WebKit/WebCore/dom/AsyncScriptRunner.cpp:87
#2  0x019e17f1 in WebCore::Timer&lt;WebCore::AsyncScriptRunner&gt;::fired (this=0x35c62f4) at third_party/WebKit/WebCore/platform/Timer.h:98
#3  0x015d33b1 in WebCore::ThreadTimers::sharedTimerFiredInternal (this=0x32a5d00) at third_party/WebKit/WebCore/platform/ThreadTimers.cpp:112
#4  0x015d3495 in WebCore::ThreadTimers::sharedTimerFired () at third_party/WebKit/WebCore/platform/ThreadTimers.cpp:90
#5  0x01074882 in webkit_glue::WebKitClientImpl::DoTimeout (this=0x31d8e60) at ./webkit/glue/webkitclient_impl.h:68
#6  0x010749a7 in DispatchToMethod&lt;webkit_glue::WebKitClientImpl, void (webkit_glue::WebKitClientImpl::*)()&gt; (this=0x32a5b60) at ./base/tuple.h:537
#7  base::BaseTimer&lt;webkit_glue::WebKitClientImpl, false&gt;::TimerTask::Run (this=0x32a5b60) at ./base/timer.h:160
#8  0x009cc66b in MessageLoop::RunTask (this=0xb1e5a1dc, task=0x32a5b60) at base/message_loop.cc:418
#9  0x009cdc0e in MessageLoop::DeferOrRunPendingTask (this=0xb1e5a1dc, pending_task=...) at base/message_loop.cc:427
#10 0x009cdefc in MessageLoop::DoWork (this=0xb1e5a1dc) at base/message_loop.cc:534
#11 0x009cff20 in base::MessagePumpDefault::Run (this=0x3162400, delegate=0xb1e5a1dc) at base/message_pump_default.cc:23
#12 0x009cd134 in MessageLoop::RunInternal (this=0xb1e5a1dc) at base/message_loop.cc:266
#13 0x009cd25d in MessageLoop::RunHandler (this=0x35c62f4) at base/message_loop.cc:238
#14 MessageLoop::Run (this=0x35c62f4) at base/message_loop.cc:216
#15 0x009eff9d in base::Thread::Run (this=0x31276c0, message_loop=0xb1e5a1dc) at base/thread.cc:140
#16 0x009f05ab in base::Thread::ThreadMain (this=0x31276c0) at base/thread.cc:164
#17 0x009de951 in ThreadFunc (closure=0x31276c0) at base/platform_thread_posix.cc:35
#18 0xb75db96e in start_thread (arg=0xb1e5ab70) at pthread_create.c:300
#19 0xb7153a4e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130

Copied from http://crbug.com/63302

On TOT debug build, we hit the assertion in ScriptElement::notifyFinished:
void ScriptElement::notifyFinished(CachedResource* o)
{
    ASSERT_UNUSED(o, o == m_cachedScript);
    m_element-&gt;document()-&gt;asyncScriptRunner()-&gt;executeScriptSoon(this, m_cachedScript);
    m_cachedScript = 0;
}
which is added by http://trac.webkit.org/changeset/42665</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>312494</commentid>
    <comment_count>1</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2010-11-22 13:46:38 -0800</bug_when>
    <thetext>The timer seems to be firing after the script element has been removed from the document but I can&apos;t reproduce reliably.  In fact, attaching a breakpoint almost always prevent the crash from happening. We need some loader experts here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>312982</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2010-11-23 12:50:38 -0800</bug_when>
    <thetext>The problem is that we&apos;re calling notifyFinished in ScriptElement::requestScript because it does m_cachedScript-&gt;addClient(this), while notifyFinished is also called by didFinishLoading.

You can see the sequence of events as follows:

didFinishLoading: file:///Users/rniwa/Desktop/crbug63302.svg#bar
0x105f62c10: stopLoadRequest, 0x105f701a0
0x105f62c10: stopLoadRequest, 0x0
0x105f5fda0: requestScript, 0x0
    0x105f5fda0: notifyFinished, 0x105f701a0
0x105f5fda0: stopLoadRequest, 0x0
0x105f62c10: requestScript, 0x0
    0x105f62c10: notifyFinished, 0x105f701a0 &lt; this call clears m_cachedScript
0x105f62c10: notifyFinished, 0x0 &lt; oops! m_cachedScript is gone already
ASSERTION FAILED: o == m_cachedScript

I feel like ScriptElement::requestScript shouldn&apos;t be calling addClient but I&apos;m not confident.  The stack trace for the first call to notifyFinished is:

#0	0x101fb02c0 in WebCore::ScriptElement::notifyFinished at ScriptElement.cpp:245
#1	0x101549f24 in WebCore::CachedResource::didAddClient at CachedResource.cpp:222
#2	0x10154b28b in WebCore::CachedResource::addClient at CachedResource.cpp:216
#3	0x101fb0655 in WebCore::ScriptElement::requestScript at ScriptElement.cpp:171
#4	0x101fb11f2 in WebCore::ScriptElement::insertedIntoDocument at ScriptElement.cpp:78
#5	0x1020c8737 in WebCore::SVGScriptElement::insertedIntoDocument at SVGScriptElement.cpp:99
#6	0x10159eb3a in WebCore::ContainerNode::insertedIntoDocument at ContainerNode.cpp:728
#7	0x1017f5ba2 in WebCore::Element::insertedIntoDocument at Element.cpp:858
#8	0x102054195 in WebCore::SVGElement::insertedIntoDocument at SVGElement.cpp:295
#9	0x1020d2d29 in WebCore::SVGStyledElement::insertedIntoDocument at SVGStyledElement.cpp:274
#10	0x1020f1089 in WebCore::SVGUseElement::insertedIntoDocument at SVGUseElement.cpp:125
#11	0x10159dcca in WebCore::notifyChildInserted at ContainerNode.cpp:1015
#12	0x10159ff99 in WebCore::ContainerNode::appendChild at ContainerNode.cpp:604
#13	0x1020f2c4b in WebCore::SVGUseElement::buildShadowTree at SVGUseElement.cpp:780
#14	0x1020f3699 in WebCore::SVGUseElement::buildShadowAndInstanceTree at SVGUseElement.cpp:538
#15	0x101f1d2ec in WebCore::RenderSVGShadowTreeRootContainer::updateFromElement at RenderSVGShadowTreeRootContainer.cpp:77
#16	0x1020f2de6 in WebCore::SVGUseElement::recalcStyle at SVGUseElement.cpp:346
#17	0x1017f5922 in WebCore::Element::recalcStyle at Element.cpp:1041
#18	0x1016d095c in WebCore::Document::recalcStyle at Document.cpp:1574
#19	0x1016d062f in WebCore::Document::updateStyleIfNeeded at Document.cpp:1616
#20	0x1016c949d in WebCore::Document::updateStyleForAllDocuments at Document.cpp:1633
#21	0x101fa639c in WebCore::ScriptController::executeScript at ScriptControllerBase.cpp:64
#22	0x102186d54 in WebCore::XMLDocumentParser::notifyFinished at XMLDocumentParser.cpp:362</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>312983</commentid>
    <comment_count>3</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2010-11-23 12:52:15 -0800</bug_when>
    <thetext>Notation for the output:
this: &lt;function name&gt;, m_cachedScript</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>337704</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-01-20 16:38:04 -0800</bug_when>
    <thetext>&lt;rdar://problem/8895819&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>337705</commentid>
    <comment_count>5</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-01-20 16:41:28 -0800</bug_when>
    <thetext>Actually, can you still reproduce this? I tried opening the demo in Safari/WebKit 5.0.3 and in r76045, but couldn&apos;t get a crash.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>338145</commentid>
    <comment_count>6</comment_count>
    <who name="Tony Gentilcore">tonyg</who>
    <bug_when>2011-01-21 10:26:57 -0800</bug_when>
    <thetext>The test case doesn&apos;t repro for me either on r76356 (osx 10.6).

rniwa, please reopen if you still believe this to be an issue.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>74591</attachid>
            <date>2010-11-22 13:41:04 -0800</date>
            <delta_ts>2010-11-22 13:41:04 -0800</delta_ts>
            <desc>demo</desc>
            <filename>crbug63302.svg</filename>
            <type>image/svg+xml</type>
            <size>214</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1s
bnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgogICAgPHVzZSB4bGluazpo
cmVmPSIjZm9vIj48L3VzZT4KICAgIDx1c2UgaWQ9ImZvbyIgPgogICAgICAgIDxzY3JpcHQgeGxp
bms6aHJlZj0iI2JhciI+PC9zY3JpcHQ+CiAgICA8L3VzZT4KPC9zdmc+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>