<?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>198993</bug_id>
          
          <creation_ts>2019-06-19 00:31:09 -0700</creation_ts>
          <short_desc>[Curl] CurlRequestScheduler doesn&apos;t terminate worker thread in a certain situation.</short_desc>
          <delta_ts>2019-06-19 21:16:42 -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>Platform</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <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="Takashi Komori">takashi.komori</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>basuke</cc>
    
    <cc>commit-queue</cc>
    
    <cc>don.olmstead</cc>
    
    <cc>fujii</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1545996</commentid>
    <comment_count>0</comment_count>
    <who name="Takashi Komori">takashi.komori</who>
    <bug_when>2019-06-19 00:31:09 -0700</bug_when>
    <thetext>When a CurlRequest receives didReceiveDataCallback from libcurl, it append a task for main thread by calling callClient.
If CurlRequest::invalidateClient is called before the task is processed, the task will not be processed properly.
This is because invalidateClient changes m_client to nullptr and the task appended by CurlRequest::callClient checks if m_client is null.

When calling CurlRequest::didReceiveData task is not processed properly, a paused connection could remain.
In this case CurlRequestScheduler never releases the client related to it.
Eventually this causes that CurlRequestScheduler&apos;s worker thread keeps working.

This CurlRequest::invalidateClient() is called from the destructor of NetworkDataTaskCurl.
To avoid this situation, we should cancel the request before invalidate.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1545998</commentid>
    <comment_count>1</comment_count>
      <attachid>372442</attachid>
    <who name="Takashi Komori">takashi.komori</who>
    <bug_when>2019-06-19 00:56:31 -0700</bug_when>
    <thetext>Created attachment 372442
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1546015</commentid>
    <comment_count>2</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2019-06-19 03:38:08 -0700</bug_when>
    <thetext>(In reply to Takashi Komori from comment #0)
&gt; When calling CurlRequest::didReceiveData task is not processed properly, a
&gt; paused connection could remain.

Why can it remain?

&gt; In this case CurlRequestScheduler never releases the client related to it.

Really? It seems that CurlRequestScheduler calls completeTransfer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1546062</commentid>
    <comment_count>3</comment_count>
      <attachid>372442</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2019-06-19 08:11:36 -0700</bug_when>
    <thetext>Comment on attachment 372442
Patch

Clearing flags on attachment: 372442

Committed r246588: &lt;https://trac.webkit.org/changeset/246588&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1546063</commentid>
    <comment_count>4</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2019-06-19 08:11:38 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1546064</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-06-19 08:12:18 -0700</bug_when>
    <thetext>&lt;rdar://problem/51896162&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1546403</commentid>
    <comment_count>6</comment_count>
    <who name="Takashi Komori">takashi.komori</who>
    <bug_when>2019-06-19 20:54:18 -0700</bug_when>
    <thetext>(In reply to Fujii Hironori from comment #2)
&gt; (In reply to Takashi Komori from comment #0)
&gt; &gt; When calling CurlRequest::didReceiveData task is not processed properly, a
&gt; &gt; paused connection could remain.
&gt; 
&gt; Why can it remain?
&gt; 
&gt; &gt; In this case CurlRequestScheduler never releases the client related to it.
&gt; 
&gt; Really? It seems that CurlRequestScheduler calls completeTransfer.

To be precise, the task added by didreceiveData is not processed properly.
And when that task is not processed, the connection rmains paused.


CurlRequest::didReceiveData (PAUSE)
CurlRequest::invokeDidReceiveResponse
|
| (Add task by using callClient)
| 
NetworkDataTaskCurl::curlDidReceiveResponse
NetworkDataTaskCurl::invokeDidReceiveResponse
CurlRequest::completeDidReceiveResponse (UNPAUSE)
CrrlRequest::didCompleteTransfer


In this case, paused connection won&apos;t return CURLMSG_DONE message and CurlRequestScheduler::completeTransfer will not be invoked.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1546412</commentid>
    <comment_count>7</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2019-06-19 21:16:42 -0700</bug_when>
    <thetext>I got the idea. Thanks.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>372442</attachid>
            <date>2019-06-19 00:56:31 -0700</date>
            <delta_ts>2019-06-19 08:11:36 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-198993-20190619165415.patch</filename>
            <type>text/plain</type>
            <size>1569</size>
            <attacher name="Takashi Komori">takashi.komori</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjQ2NTU4CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViS2l0L0No
YW5nZUxvZyBiL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nCmluZGV4IDg1YmQ0YWYzZTI5OGNhODEw
ZjVhMGU2YmI0OTJiMTZjMjAyNWMxZ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