<?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>185134</bug_id>
          
          <creation_ts>2018-04-30 09:44:44 -0700</creation_ts>
          <short_desc>Fix bad use of RunLoop::main().dispatch() in MessagePort::dispatchMessages()</short_desc>
          <delta_ts>2018-04-30 16:28:10 -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>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=185073</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Chris Dumez">cdumez</reporter>
          <assigned_to name="Chris Dumez">cdumez</assigned_to>
          <cc>ap</cc>
    
    <cc>beidson</cc>
    
    <cc>cdumez</cc>
    
    <cc>commit-queue</cc>
    
    <cc>dbates</cc>
    
    <cc>esprehn+autocc</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>ggaren</cc>
    
    <cc>kangil.han</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1419003</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-04-30 09:44:44 -0700</bug_when>
    <thetext>Fix bad use of RunLoop::main().dispatch() in MessagePort::dispatchMessages(). This code runs on iOS WebKitLegacy and it is therefore unsafe to use RunLoop::main() here. We want to use callOnMainThread() instead to run code on the WebThread.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419005</commentid>
    <comment_count>1</comment_count>
      <attachid>339116</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-04-30 09:45:42 -0700</bug_when>
    <thetext>Created attachment 339116
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419009</commentid>
    <comment_count>2</comment_count>
      <attachid>339116</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2018-04-30 09:51:44 -0700</bug_when>
    <thetext>Comment on attachment 339116
Patch

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419047</commentid>
    <comment_count>3</comment_count>
      <attachid>339116</attachid>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2018-04-30 10:59:25 -0700</bug_when>
    <thetext>Comment on attachment 339116
Patch

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

&gt; Source/WebCore/dom/MessagePort.cpp:-287
&gt; -            RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] {

Is there anything that we can do to prevent this kind of mistake from the getgo? It seems to be repeatedly made.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419060</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-04-30 11:50:35 -0700</bug_when>
    <thetext>(In reply to Daniel Bates from comment #3)
&gt; Comment on attachment 339116 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=339116&amp;action=review
&gt; 
&gt; &gt; Source/WebCore/dom/MessagePort.cpp:-287
&gt; &gt; -            RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] {
&gt; 
&gt; Is there anything that we can do to prevent this kind of mistake from the
&gt; getgo? It seems to be repeatedly made.

I agree it would be nice. Maybe we could introduce a rule enforced by the style checker that RunLoop::main().dispatch() should never be used in WebCore? I don&apos;t have a better idea at the moment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419067</commentid>
    <comment_count>5</comment_count>
      <attachid>339116</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2018-04-30 12:13:38 -0700</bug_when>
    <thetext>Comment on attachment 339116
Patch

Clearing flags on attachment: 339116

Committed r231161: &lt;https://trac.webkit.org/changeset/231161&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419068</commentid>
    <comment_count>6</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2018-04-30 12:13:40 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419069</commentid>
    <comment_count>7</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-04-30 12:14:31 -0700</bug_when>
    <thetext>&lt;rdar://problem/39843751&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419113</commentid>
    <comment_count>8</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2018-04-30 14:16:25 -0700</bug_when>
    <thetext>(In reply to Chris Dumez from comment #4)
&gt; (In reply to Daniel Bates from comment #3)
&gt; &gt; Comment on attachment 339116 [details]
&gt; &gt; Patch
&gt; &gt; 
&gt; &gt; View in context:
&gt; &gt; https://bugs.webkit.org/attachment.cgi?id=339116&amp;action=review
&gt; &gt; 
&gt; &gt; &gt; Source/WebCore/dom/MessagePort.cpp:-287
&gt; &gt; &gt; -            RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] {
&gt; &gt; 
&gt; &gt; Is there anything that we can do to prevent this kind of mistake from the
&gt; &gt; getgo? It seems to be repeatedly made.
&gt; 
&gt; I agree it would be nice. Maybe we could introduce a rule enforced by the
&gt; style checker that RunLoop::main().dispatch() should never be used in
&gt; WebCore? I don&apos;t have a better idea at the moment.

Notice that the WebThread code is guarded by USE(WEB_THREAD) and we only enable this feature on iOS. Can we take advantage of this together with a static_assert() to cause a compile-time failure with a helpful message whenever someone makes use unsafe or potentially unsafe RunLoop functionality, including RunLoop::main().dispatch()?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1419165</commentid>
    <comment_count>9</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-04-30 16:28:10 -0700</bug_when>
    <thetext>(In reply to Daniel Bates from comment #8)
&gt; (In reply to Chris Dumez from comment #4)
&gt; &gt; (In reply to Daniel Bates from comment #3)
&gt; &gt; &gt; Comment on attachment 339116 [details]
&gt; &gt; &gt; Patch
&gt; &gt; &gt; 
&gt; &gt; &gt; View in context:
&gt; &gt; &gt; https://bugs.webkit.org/attachment.cgi?id=339116&amp;action=review
&gt; &gt; &gt; 
&gt; &gt; &gt; &gt; Source/WebCore/dom/MessagePort.cpp:-287
&gt; &gt; &gt; &gt; -            RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] {
&gt; &gt; &gt; 
&gt; &gt; &gt; Is there anything that we can do to prevent this kind of mistake from the
&gt; &gt; &gt; getgo? It seems to be repeatedly made.
&gt; &gt; 
&gt; &gt; I agree it would be nice. Maybe we could introduce a rule enforced by the
&gt; &gt; style checker that RunLoop::main().dispatch() should never be used in
&gt; &gt; WebCore? I don&apos;t have a better idea at the moment.
&gt; 
&gt; Notice that the WebThread code is guarded by USE(WEB_THREAD) and we only
&gt; enable this feature on iOS. Can we take advantage of this together with a
&gt; static_assert() to cause a compile-time failure with a helpful message
&gt; whenever someone makes use unsafe or potentially unsafe RunLoop
&gt; functionality, including RunLoop::main().dispatch()?

RunLoop is in WTF and USE_WEB_THREAD is set to 1 when building WTF on iOS. Therefore, the static_assert(!USE_WEB_THREAD, &quot;&quot;) would cause a build error on iOS, even though it is perfectly fine to call RunLoop::main().dispatch() from iOS WebKit2 code. I might be missing something.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>339116</attachid>
            <date>2018-04-30 09:45:42 -0700</date>
            <delta_ts>2018-04-30 12:13:38 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-185134-20180430094541.patch</filename>
            <type>text/plain</type>
            <size>1818</size>
            <attacher name="Chris Dumez">cdumez</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjMxMTU2CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggOTRhZDIwNzBhNGVhMzQ4
ZGM0MjAyNmYxOGI3NzdkODc1OTU3NTNkNi4uN2NkMTFlZGNmM2Y1ZjE1MWJhZTI1ODdkZTZiMzRk
MmM1NmU3ZThlYiAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE3IEBACisyMDE4LTA0LTMwICBDaHJp
cyBEdW1leiAgPGNkdW1lekBhcHBsZS5jb20+CisKKyAgICAgICAgRml4IGJhZCB1c2Ugb2YgUnVu
TG9vcDo6bWFpbigpLmRpc3BhdGNoKCkgaW4gTWVzc2FnZVBvcnQ6OmRpc3BhdGNoTWVzc2FnZXMo
KQorICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTg1MTM0
CisKKyAgICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgRml4IGJh
ZCB1c2Ugb2YgUnVuTG9vcDo6bWFpbigpLmRpc3BhdGNoKCkgaW4gTWVzc2FnZVBvcnQ6OmRpc3Bh
dGNoTWVzc2FnZXMoKS4gVGhpcyBjb2RlIHJ1bnMgb24gaU9TIFdlYktpdExlZ2FjeQorICAgICAg
ICBhbmQgaXQgaXMgdGhlcmVmb3JlIH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