-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
tcpkeepalive: add CURLOPT_TCP_KEEPCNT
for libcurl
and keepalive-cnt
for curl
#13885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CURLOPT_TCP_KEEPCNT
for libcurl
and keepalive-probes
for curl
CURLOPT_TCP_KEEPCNT
for libcurl
and keepalive-cnt
for curl
Hah, this CI failure seems to be caused by this change? I'm not sure, I wonder if changing the option from 1 to 9 or 10 would fix it. |
Not necessarily, it might also just be a flaky test/build... |
My question would be when users run curl on a new platform, should they expect
to see platform default behaviour or curl default behaviour? I would venture
that platform default behavior is more to be expected. These are low-level
details that are expected to be different on different OSes; that's what makes
different OSes different, after all. Or, from another perspective, why stop at
trying to make TCP keepalive behaviour the same across platforms? Why not make
ephemeral port ranges the same, or socket buffer sizes the same, etc., etc.?
|
Not all system default behaviors are rational, sometimes they're even lame. Take the TCP keep-alive for instance, most of the platforms use 2 hours as the default value of
We should only try to consolidate the behaviors for libraries that aim to be cross-platform and portable (and I believe this has also been |
When can we get the review started? Would you take a glance at this PR? @bagder |
Thanks! |
Upcoming in curl v8.9.0. Ref: curl/curl@b77d627 Ref: curl/curl#13885
Customizing
TCP_KEEPIDLE
andTCP_KEEPINTVL
forcurl
has been supported since v7.18.0, withTCP_KEEPCNT
missing all the time.TCP_KEEPIDLE
,TCP_KEEPINTVL
, andTCP_KEEPCNT
are not included in the POSIX standard for system callsetsockopts()
, yet while these three socket options are widely available on most Unix-like systems and Windows.I reckon that
curl
should support settingTCP_KEEPCNT
and use a default value if unspecified across all platforms based off of the following justification:The system default value of
TCP_KEEPCNT
varies across different platforms that support this option: the maximum number of keep-alive probes sent before dropping the connection is 8 on *BSD/macOS/AIX, 9 on Linux/AIX(old), 5/10 on Windows (5 on Windows Server 2003, Windows XP, and Windows 2000, 10 on Windows Vista and later), or even more unorthodox, undefined default value on Solaris/illumos, and so on, which brings forth the inconsistency ofcurl
on various platforms when it comes to the behaviors of TCP keep-alive mechanism. Setting up a default value forTCP_KEEPCNT
regardless of specific platforms will consolidate the behaviors of TCP keep-alive.The requirement of precisely tuning the TCP keep-alive behaviors for some purposes: 1) aggressive default values of TCP keep-alive can result in excessive CPU consumption and drain the battery fast if it's on mobile devices (that are tolerant with dead connections), people can alleviate it by tuning up
TCP_KEEPINTVL
and tuning downTCP_KEEPCNT
, 2) on the contrary, for some applications that are aliveness-sensitive about the remote peers, people need to tune down both theTCP_KEEPINTVL
andTCP_KEEPCNT
to detect the dead peers ASAP.Thus, the support of the full TCP keep-alive mechanism (all three options) enables users to take control of the TCP keep-alive mechanism more finely and build more superior applications based on
curl
/liburl
.References
Mac OS
In earlier versions, macOS only supported setting
TCP_KEEPALIVE
(the equivalent ofTCP_KEEPIDLE
on other platforms), but since macOS 10.8 it has supportedTCP_KEEPINTVL
andTCP_KEEPCNT
.Check out this mailing list and the source code for more details.
Solaris
Solaris claimed it supported the TCP keep-alive mechanism, but
TCP_KEEPIDLE
,TCP_KEEPINTVL
, andTCP_KEEPCNT
were not available on Solaris until the latest version 11.4. Therefore, we need to simulate the TCP keep-alive mechanism on other platforms viaTCP_KEEPALIVE_THRESHOLD
+TCP_KEEPALIVE_ABORT_THRESHOLD
.Relevant issues
#8564
#10318