<?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>227118</bug_id>
          
          <creation_ts>2021-06-17 04:53:02 -0700</creation_ts>
          <short_desc>[Curl] Add curl option CURLOPT_NOSIGNAL to omit numerous sigaction calls</short_desc>
          <delta_ts>2021-06-20 18:18:51 -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>WebKit Nightly Build</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Other</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>Minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Souju TANAKA">sojulibra</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>basuke</cc>
    
    <cc>chris.reid</cc>
    
    <cc>don.olmstead</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>fujii</cc>
    
    <cc>galpeter</cc>
    
    <cc>stephan.szabo</cc>
    
    <cc>takashi.komori</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1770591</commentid>
    <comment_count>0</comment_count>
    <who name="Souju TANAKA">sojulibra</who>
    <bug_when>2021-06-17 04:53:02 -0700</bug_when>
    <thetext>When large number of files are added to download queue at once, the download speed gets significantly slower on a platform we are working for. We found that the most part of time are consumed for sigaction system call in curl.
- https://github.com/curl/curl/blob/84d2839740ca78041ac7419d9aaeac55c1e1c729/lib/sigpipe.h#L52
- https://github.com/curl/curl/blob/84d2839740ca78041ac7419d9aaeac55c1e1c729/lib/sigpipe.h#L56
- https://github.com/curl/curl/blob/84d2839740ca78041ac7419d9aaeac55c1e1c729/lib/sigpipe.h#L69

The number of times of sigaction call becomes enormously as we increase file handles registered by curl_multi_add_handle(). Here is the test results that show the total count of sigaction calls with different number of file handles. Each file size is 64KB.
  * 512 files (32MB in total): 348144 times (of sigaction call)
  * 1024 files (64MB in total): 1344192 times
  * 2048 files (128MB in total): 5300697 times
  * 4096 files (256MB in total): 21088311 times
It seems the times of sigaction-call grow along O(N^2) where N is the number of file handles.

The sigaction is there to ignore SIGPIPE signals that is triggered when the other end of socket are closed. However for the platform we are targeting, we have little concern about the unexpected signals since the socket are configured with SO_NOSIGPIPE option with setsockopt(), and use send() with MSG_NOSIGNAL as its forth argument. 
- https://github.com/curl/curl/blob/ee97f176970c9667bfbdaab89bc637e77099d1df/lib/connect.c#L1085-L1086
- https://github.com/curl/curl/blob/ee97f176970c9667bfbdaab89bc637e77099d1df/lib/curl_setup_once.h#L116
Also curl with c-ares or threaded async DNS resolver doesn&apos;t rely on SIGALRM signal to detect timeouts.

The cost of syscall is relatively high because of user-kernel context switching. These sigaction can be avoided by a curl option, CURLOPT_NOSIGNAL (https://curl.se/libcurl/c/CURLOPT_NOSIGNAL.html). With the option enabled, curl omits to install signal handlers by assuming no signals triggered for the process.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1770941</commentid>
    <comment_count>1</comment_count>
      <attachid>431756</attachid>
    <who name="Souju TANAKA">sojulibra</who>
    <bug_when>2021-06-17 23:12:25 -0700</bug_when>
    <thetext>Created attachment 431756
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1771058</commentid>
    <comment_count>2</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2021-06-18 13:17:52 -0700</bug_when>
    <thetext>Why does curl block SIGPIPE even on platforms supporting MSG_NOSIGNAL and SO_NOSIGPIPE?
Increasing sigaction calls as O(N^2) seems like a curl bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1771062</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2021-06-18 13:41:44 -0700</bug_when>
    <thetext>Committed r279046 (238966@main): &lt;https://commits.webkit.org/238966@main&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 431756.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1771063</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-06-18 13:42:31 -0700</bug_when>
    <thetext>&lt;rdar://problem/79512069&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1771204</commentid>
    <comment_count>5</comment_count>
    <who name="Souju TANAKA">sojulibra</who>
    <bug_when>2021-06-20 18:18:51 -0700</bug_when>
    <thetext>Not all systems provide enough way to avoid SIGPIPE. SO_NOSIGPIPE socket option is available in BSD based OS. MSG_NOSIGNAL flag has been brought in since Linux 2.2.

Thank you for your review.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>431756</attachid>
            <date>2021-06-17 23:12:25 -0700</date>
            <delta_ts>2021-06-18 13:41:45 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-227118-20210618074803.patch</filename>
            <type>text/plain</type>
            <size>1637</size>
            <attacher name="Souju TANAKA">sojulibra</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDI3OTAzMCkKKysrIFNvdXJjZS9XZWJDb3JlL0NoYW5n
ZUxvZwkod29ya2luZyBjb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3ICBTYWlkIEFib3UtSGFsbGF3YSAgPHNhaWRAYXBw
bGUuY29tPgogCiAgICAgICAgIFtDb2NvYV0gRGlzYWJsZSBoYXJkd2FyZSBkZWNvZGluZyBpbiB0
aGUgV2ViUHJvY2VzcwpJbmRleDogU291cmNlL1dlYkNvcmUvcGxhdGZvcm0vbmV0d29yay9jdXJs
L0N1cmxDb250ZXh0LmNwcAo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2ViQ29yZS9wbGF0Zm9ybS9u
ZXR3b3JrL2N1cmwvQ3VybENvbnRleHQuY3BwCShyZXZpc2lvbiAyNzg4MjMpCisrKyBTb3VyY2Uv
V2ViQ29yZS9wbGF0Zm9ybS9uZXR3b3JrL2N1cmwvQ3VybENvbnRleHQuY3BwCSh3b3JraW5nIGNv
cHkpCkBAIC0yODIsNiArMjgyLDcgQEAgQ3VybEhhbmRsZTo6Q3VybEhhbmRsZSgpCiB7CiAgICAg
bV9oYW5kbGUgPSBjdXJsX2Vhc3lfaW5pdCgpOwogICAgIGN1cmxfZWFzeV9zZXRvcHQobV9oYW5k
bGUsIENVUkxPUFRfRVJST1JCVUZGRVIsIG1fZXJyb3JCdWZmZXIpOworICAgIGN1cmxfZWFzeV9z
ZXRvcHQobV9oYW5kbGUsIENVUkxPUFRfTk9TSUdOQUwsIDFMKTsKIAogICAgIGVuYWJsZVNoYXJl
SGFuZGxlKCk7CiAgICAgZW5hYmxlQWxsb3dlZFByb3RvY29scygpOwo=
</data>

          </attachment>
      

    </bug>

</bugzilla>