<?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>181017</bug_id>
          
          <creation_ts>2017-12-19 20:56:18 -0800</creation_ts>
          <short_desc>ASSERT in MessagePort shutdown code</short_desc>
          <delta_ts>2017-12-19 23:01:39 -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>WebCore Misc.</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>94458</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Brady Eidson">beidson</reporter>
          <assigned_to name="Brady Eidson">beidson</assigned_to>
          <cc>cdumez</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1383530</commentid>
    <comment_count>0</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2017-12-19 20:56:18 -0800</bug_when>
    <thetext>ASSERT in MessagePort shutdown code

Ran across this while working on MessagePorts for Service Workers.

The following command in a debug build:
run-webkit-tests fast/events/message-port-constructor-for-deleted-document.html fast/events/message-port-context-destroyed.html

Results in the following:

ASSERTION FAILED: m_closed
/Users/bradeeoh/git/OpenSource/Source/WebCore/dom/MessagePort.cpp(138) : void WebCore::MessagePort::contextDestroyed()
1   0x112a3d72d WTFCrash
2   0x11b260cf3 WebCore::MessagePort::contextDestroyed()
3   0x11b2d9a3a WebCore::ScriptExecutionContext::~ScriptExecutionContext()
4   0x11b16e1bd WebCore::Document::~Document()
5   0x11b4ac775 WebCore::HTMLDocument::~HTMLDocument()
6   0x11b4ac795 WebCore::HTMLDocument::~HTMLDocument()
7   0x11b4ac879 WebCore::HTMLDocument::~HTMLDocument()
8   0x11b16f570 WebCore::Document::decrementReferencingNodeCount()
9   0x11b16f2c4 WebCore::Document::removedLastRef()
10  0x11b293eb7 WebCore::Node::removedLastRef()
11  0x119496db3 WebCore::Node::deref()
12  0x11b28a1d5 WebCore::Node::derefEventTarget()
13  0x1197b3bc6 WebCore::EventTarget::deref()
14  0x1197b3b9f WTF::Ref&lt;WebCore::EventTarget, WTF::DumbPtrTraits&lt;WebCore::EventTarget&gt; &gt;::~Ref()
15  0x1197a18a5 WTF::Ref&lt;WebCore::EventTarget, WTF::DumbPtrTraits&lt;WebCore::EventTarget&gt; &gt;::~Ref()
16  0x119c52219 WebCore::JSDOMWrapper&lt;WebCore::EventTarget&gt;::~JSDOMWrapper()
17  0x119c521f5 WebCore::JSEventTarget::~JSEventTarget()
18  0x119c49fd5 WebCore::JSEventTarget::~JSEventTarget()
19  0x119c46c1d WebCore::JSEventTarget::destroy(JSC::JSCell*)
....

So the ScriptExecutionContext is being destroyed but hasn&apos;t told its MessagePorts to close.

It normally tells its MessagePorts to close inside stopActiveDOMObjects.

This test is arranged such that stopActiveDOMObjects is called, *then* a MessagePort is added later, and therefore that MessagePort is never told to close.

Of course the real problem is that MessagePorts are added after stopActiveDOMObjects is called - &quot;Active DOM Objects&quot; and similar objects should not be added then.

Indeed if I add an ASSERT inside ScriptExecutionContext::createdMessagePort:
    ASSERT(!m_activeDOMObjectsAreStopped);

It fires.

So that&apos;s the bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383544</commentid>
    <comment_count>1</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2017-12-19 22:29:06 -0800</bug_when>
    <thetext>This can easily be fixed by making MessagePort an ActiveDOMObject, as some comments allude.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383545</commentid>
    <comment_count>2</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2017-12-19 22:30:27 -0800</bug_when>
    <thetext>Annoyingly, this required interactions between multiple tests that - apparently - weren&apos;t happening in normal run-webkit-test runs.

I&apos;m going to try to reproduce standalone first.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383546</commentid>
    <comment_count>3</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2017-12-19 22:36:03 -0800</bug_when>
    <thetext>(Maybe this test was skipped? 272 out of 791 in fast/events are skipped!!!)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383548</commentid>
    <comment_count>4</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2017-12-19 23:01:39 -0800</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 94458 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>