From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: TCP_KEEPINVTL and TCP_KEEPIDLE - Socket Keep Alives not working
Date: Wed, 1 Jul 2020 21:50:27 +0200 [thread overview]
Message-ID: <20200701195027.GL3499@calimero.vinschen.de> (raw)
In-Reply-To: <20200630165358.GG3499@calimero.vinschen.de>
On Jun 30 18:53, Corinna Vinschen wrote:
> On Jun 30 09:46, Cary Lewis via Cygwin wrote:
> > Thanks for the reply. The answer to your question is that the 2 hour keep
> > alive was not sufficient for a particular use case I encountered.
> >
> > I was trying to use curl under cygwin to access a very slow REST endpoint
> > that was taking up to 8 minutes to generate download before any data flowed
> > back to the client. This caused the server to abort the socket.
> >
> > Accessing the endpoint in chrome or firefox revealed that they set a
> > keepalive to 45 seconds, which kept the server happy.
> >
> > Attempting to set --keepalive-time=45 in cygwin's curl didn't work, and
> > wireshark revealed that no keepalives were being sent.
> >
> > I will attempt to patch cygwin, I got the build to work. Can you point me
> > in the right direction, in terms of where the socket calls get mapped to
> > the winsock calls?
>
> Actually, while I'm usually happy to take contributions, you don't have
> to dig into that yourself. I already have a few local patches in the
> loop changing some of the affected code. I have a good idea what's
> required to add the keep-alive socket options to that code, so just lay
> back and stay tuned for now.
Ok, so I added support for a couple more IPPROTO_TCP socket options.
First of all I fixed TCP_MAXSEG which was using the BSD value, rather
than the WinSock value. Then I added TCP_FASTOPEN, TCP_KEEPIDLE,
TCP_KEEPCNT, TCP_KEEPINTVL, TCP_QUICKACK and TCP_USER_TIMEOUT:
- TCP_FASTOPEN is supported since W10 1607, it's just faked on older
systems.
- TCP_KEEPIDLE, TCP_KEEPCNT, TCP_KEEPINTVL are using the options
of the same name since W10 1709, WSAIoctl(SIO_KEEPALIVE_VALS)
on older systems.
But here's a problem: Older systems didn't allow to change
TCP_KEEPCNT. It is always fixed to 10. Mulling over that problem in
the shower, I came up with the following solution:
The max keep-alive timeout is TCP_KEEPIDLE + TCP_KEEPCNT * TCP_KEEPINTVL.
This should stay the same from a user space perspective. So the current
code tweaks the TCP_KEEPINTVL given to WinSock so that
TCP_KEEPCNT * user space TCP_KEEPINTVL == 10 * WinSock TCP_KEEPINTVL
Example: user space TCP_KEEPCNT 4, TCP_KEEPINTVL 5 (4 * 5 == 20)
==> WinSock TCP_KEEPCNT 10, TCP_KEEPINTVL 2 (10 * 2 == 20)
I hope that makes sense.
- TCP_USER_TIMEOUT is supported with msec granularity since W10 1607
(called TCP_MAXRTMS), with 1 secs granularity on older systems
(called TCP_MAXRT). Use the latter on older systems under the expected
loss of precision.
- TCP_QUICKACK is supposedly supported on Windows as a socket option
but it's still not clear if the net got that right so far. However,
there's WSAIoctl(SIO_TCP_SET_ACK_FREQUENCY) doing the same.
I uploaded developer snapshots to https://cygwin.com/snapshots/,
please test.
For testing, you'll need at least the DLL, plus the changed headers
cygwin/socket.h and netinet/tcp.h from the complete tar file
cygwin-20200701.tar.xz. Or, just take the DLL and fetch the headers
right from the git repo.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
next prev parent reply other threads:[~2020-07-01 19:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-07 13:20 Cary Lewis
2020-06-07 18:19 ` Ken Brown
2020-06-07 18:56 ` Cary Lewis
2020-06-30 11:12 ` Corinna Vinschen
2020-06-30 13:46 ` Cary Lewis
2020-06-30 16:53 ` Corinna Vinschen
2020-07-01 19:50 ` Corinna Vinschen [this message]
2020-07-02 14:52 ` Cary Lewis
2020-07-13 13:05 ` Cary Lewis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200701195027.GL3499@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).