Skip to content

Commit 0474a27

Browse files
authored
deps: libuv: revert 3a9a6e3e6b
This commit reverts "tcp: support customizing TCP_KEEPINTVL and TCP_KEEPCNT". Without this revert, we see a lot of flakyness on Windows CI. PR-URL: #62511 Refs: libuv/libuv@3a9a6e3 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5ece312 commit 0474a27

8 files changed

Lines changed: 59 additions & 198 deletions

File tree

‎deps/uv/docs/src/tcp.rst‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,6 @@ API
9191
9292
.. versionchanged:: 1.49.0 If `delay` is less than 1 then ``UV_EINVAL``` is returned.
9393
94-
.. c:function:: int uv_tcp_keepalive_ex(uv_tcp_t* handle, int on, unsigned int idle, unsigned int intvl, unsigned int cnt)
95-
96-
Enable / disable TCP keep-alive with all socket options: `TCP_KEEPIDLE`, `TCP_KEEPINTVL` and `TCP_KEEPCNT`.
97-
`idle` is the value for `TCP_KEEPIDLE`, `intvl` is the value for `TCP_KEEPINTVL`,
98-
`cnt` is the value for `TCP_KEEPCNT`, ignored when `on` is zero.
99-
100-
With TCP keep-alive enabled, `idle` is the time (in seconds) the connection needs to remain idle before
101-
TCP starts sending keep-alive probes. `intvl` is the time (in seconds) between individual keep-alive probes.
102-
TCP will drop the connection after sending `cnt` probes without getting any replies from the peer, then the
103-
handle is destroyed with a ``UV_ETIMEDOUT`` error passed to the corresponding callback.
104-
105-
If one of `idle`, `intvl`, or `cnt` is less than 1, ``UV_EINVAL`` is returned.
106-
107-
.. versionchanged:: 1.52.0 added support of setting `TCP_KEEPINTVL` and `TCP_KEEPCNT` socket options.
108-
109-
.. note::
110-
Ensure that the socket options are supported by the underlying operating system.
111-
Currently supported platforms:
112-
- AIX
113-
- DragonFlyBSD
114-
- FreeBSD
115-
- illumos
116-
- Linux
117-
- macOS
118-
- NetBSD
119-
- Solaris
120-
- Windows
121-
12294
.. c:function:: int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable)
12395
12496
Enable / disable simultaneous asynchronous accept requests that are

‎deps/uv/include/uv.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,6 @@ UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
602602
UV_EXTERNintuv_tcp_keepalive(uv_tcp_t*handle,
603603
intenable,
604604
unsigned intdelay);
605-
UV_EXTERNintuv_tcp_keepalive_ex(uv_tcp_t*handle,
606-
inton,
607-
unsigned intidle,
608-
unsigned intintvl,
609-
unsigned intcnt);
610605
UV_EXTERNintuv_tcp_simultaneous_accepts(uv_tcp_t*handle, intenable);
611606

612607
enumuv_tcp_flags {

‎deps/uv/src/unix/internal.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,7 @@ int uv__slurp(const char* filename, char* buf, size_t len);
359359
/* tcp */
360360
intuv__tcp_listen(uv_tcp_t*tcp, intbacklog, uv_connection_cbcb);
361361
intuv__tcp_nodelay(intfd, inton);
362-
intuv__tcp_keepalive(intfd,
363-
inton,
364-
unsigned intidle,
365-
unsigned intintvl,
366-
unsigned intcnt);
362+
intuv__tcp_keepalive(intfd, inton, unsigned intdelay);
367363

368364
/* tty */
369365
voiduv__tty_close(uv_tty_t*handle);

‎deps/uv/src/unix/stream.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
416416

417417
/* TODO Use delay the user passed in. */
418418
if ((stream->flags&UV_HANDLE_TCP_KEEPALIVE) &&
419-
uv__tcp_keepalive(fd, 1, 60, 1, 10)) {
419+
uv__tcp_keepalive(fd, 1, 60)) {
420420
returnUV__ERR(errno);
421421
}
422422
}

‎deps/uv/src/unix/tcp.c‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,22 @@ int uv__tcp_nodelay(int fd, int on) {
465465
#else
466466
#defineUV_KEEPALIVE_FACTOR(x)
467467
#endif
468-
intuv__tcp_keepalive(intfd,
469-
inton,
470-
unsigned intidle,
471-
unsigned intintvl,
472-
unsigned intcnt) {
468+
intuv__tcp_keepalive(intfd, inton, unsigned intdelay) {
469+
intidle;
470+
intintvl;
471+
intcnt;
472+
473+
(void) &idle;
474+
(void) &intvl;
475+
(void) &cnt;
476+
473477
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
474478
returnUV__ERR(errno);
475479

476480
if (!on)
477481
return0;
478482

479-
if (idle<1||intvl<1||cnt<1)
483+
if (delay<1)
480484
returnUV_EINVAL;
481485

482486
#ifdef__sun
@@ -502,16 +506,13 @@ int uv__tcp_keepalive(int fd,
502506
* The TCP connection will be aborted after certain amount of probes, which is set by TCP_KEEPCNT, without receiving response.
503507
*/
504508

505-
/* Kernel expects at least 10 seconds for TCP_KEEPIDLE and TCP_KEEPINTVL. */
509+
idle=delay;
510+
/* Kernel expects at least 10 seconds. */
506511
if (idle<10)
507512
idle=10;
508-
if (intvl<10)
509-
intvl=10;
510-
/* Kernel expects at most 10 days for TCP_KEEPIDLE and TCP_KEEPINTVL. */
513+
/* Kernel expects at most 10 days. */
511514
if (idle>10*24*60*60)
512515
idle=10*24*60*60;
513-
if (intvl>10*24*60*60)
514-
intvl=10*24*60*60;
515516

516517
UV_KEEPALIVE_FACTOR(idle);
517518

@@ -521,10 +522,12 @@ int uv__tcp_keepalive(int fd,
521522
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)))
522523
returnUV__ERR(errno);
523524

525+
intvl=10; /* required at least 10 seconds */
524526
UV_KEEPALIVE_FACTOR(intvl);
525527
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
526528
returnUV__ERR(errno);
527529

530+
cnt=1; /* 1 retry, ensure (TCP_KEEPINTVL * TCP_KEEPCNT) is 10 seconds */
528531
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
529532
returnUV__ERR(errno);
530533
#else
@@ -536,14 +539,15 @@ int uv__tcp_keepalive(int fd,
536539

537540
/* Note that the consequent probes will not be sent at equal intervals on Solaris,
538541
* but will be sent using the exponential backoff algorithm. */
539-
unsigned inttime_to_abort=intvl*cnt;
542+
inttime_to_abort=10; /* 10 seconds */
540543
UV_KEEPALIVE_FACTOR(time_to_abort);
541544
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, &time_to_abort, sizeof(time_to_abort)))
542545
returnUV__ERR(errno);
543546
#endif
544547

545548
#else/* !defined(__sun) */
546549

550+
idle=delay;
547551
UV_KEEPALIVE_FACTOR(idle);
548552
#ifdefTCP_KEEPIDLE
549553
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)))
@@ -555,12 +559,14 @@ int uv__tcp_keepalive(int fd,
555559
#endif
556560

557561
#ifdefTCP_KEEPINTVL
562+
intvl=1; /* 1 second; same as default on Win32 */
558563
UV_KEEPALIVE_FACTOR(intvl);
559564
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
560565
returnUV__ERR(errno);
561566
#endif
562567

563568
#ifdefTCP_KEEPCNT
569+
cnt=10; /* 10 retries; same as hardcoded on Win32 */
564570
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
565571
returnUV__ERR(errno);
566572
#endif
@@ -588,20 +594,11 @@ int uv_tcp_nodelay(uv_tcp_t* handle, int on) {
588594
}
589595

590596

591-
intuv_tcp_keepalive(uv_tcp_t*handle, inton, unsigned intidle) {
592-
returnuv_tcp_keepalive_ex(handle, on, idle, 1, 10);
593-
}
594-
595-
596-
intuv_tcp_keepalive_ex(uv_tcp_t*handle,
597-
inton,
598-
unsigned intidle,
599-
unsigned intintvl,
600-
unsigned intcnt) {
597+
intuv_tcp_keepalive(uv_tcp_t*handle, inton, unsigned intdelay) {
601598
interr;
602599

603600
if (uv__stream_fd(handle) !=-1) {
604-
err=uv__tcp_keepalive(uv__stream_fd(handle), on, idle, intvl, cnt);
601+
err=uv__tcp_keepalive(uv__stream_fd(handle), on, delay);
605602
if (err)
606603
returnerr;
607604
}
@@ -611,7 +608,7 @@ int uv_tcp_keepalive_ex(uv_tcp_t* handle,
611608
else
612609
handle->flags &= ~UV_HANDLE_TCP_KEEPALIVE;
613610

614-
/* TODO Store idle if uv__stream_fd(handle) == -1 but don't want to enlarge
611+
/* TODO Store delay if uv__stream_fd(handle) == -1 but don't want to enlarge
615612
* uv_tcp_t with an int that's almost never used...
616613
*/
617614

‎deps/uv/src/win/tcp.c‎

Lines changed: 31 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -49,98 +49,28 @@ static int uv__tcp_nodelay(uv_tcp_t* handle, SOCKET socket, int enable) {
4949
}
5050

5151

52-
/*
53-
* Check if Windows version is 10.0.16299 (Windows 10, version 1709) or later.
54-
*/
55-
staticintuv__windows10_version1709(void) {
56-
OSVERSIONINFOWos_info;
57-
if (!pRtlGetVersion)
58-
return0;
59-
pRtlGetVersion(&os_info);
60-
if (os_info.dwMajorVersion<10)
61-
return0;
62-
if (os_info.dwMajorVersion>10)
63-
return1;
64-
if (os_info.dwMinorVersion>0)
65-
return1;
66-
returnos_info.dwBuildNumber >= 16299;
67-
}
68-
69-
70-
staticintuv__tcp_keepalive(uv_tcp_t*handle,
71-
SOCKETsocket,
72-
inton,
73-
unsigned intidle,
74-
unsigned intintvl,
75-
unsigned intcnt) {
52+
staticintuv__tcp_keepalive(uv_tcp_t*handle, SOCKETsocket, intenable, unsigned intdelay) {
7653
if (setsockopt(socket,
7754
SOL_SOCKET,
7855
SO_KEEPALIVE,
79-
(constchar*)&on,
80-
sizeofon) ==-1) {
56+
(constchar*)&enable,
57+
sizeofenable) ==-1) {
8158
returnWSAGetLastError();
8259
}
8360

84-
if (!on)
61+
if (!enable)
8562
return0;
8663

87-
if (idle<1||intvl<1||cnt<1)
64+
if (delay<1)
8865
returnUV_EINVAL;
8966

90-
/* Windows 10, version 1709 (build 10.0.16299) and later require second units
91-
* for TCP keepalive options. */
92-
if (uv__windows10_version1709()) {
93-
if (setsockopt(socket,
94-
IPPROTO_TCP,
95-
TCP_KEEPIDLE,
96-
(constchar*)&idle,
97-
sizeofidle) ==-1) {
98-
returnWSAGetLastError();
99-
}
100-
101-
if (setsockopt(socket,
102-
IPPROTO_TCP,
103-
TCP_KEEPINTVL,
104-
(constchar*)&intvl,
105-
sizeofintvl) ==-1) {
106-
returnWSAGetLastError();
107-
}
108-
109-
if (setsockopt(socket,
110-
IPPROTO_TCP,
111-
TCP_KEEPCNT,
112-
(constchar*)&cnt,
113-
sizeofcnt) ==-1) {
114-
returnWSAGetLastError();
115-
}
116-
117-
return0;
118-
}
119-
120-
/* For those versions prior to Windows 10 version 1709,
121-
* we fall back to SIO_KEEPALIVE_VALS that expects millisecond units.
122-
* The SIO_KEEPALIVE_VALS IOCTL is supported on Windows 2000
123-
* and later versions of the operating system. */
124-
structtcp_keepalivekeepalive;
125-
keepalive.onoff=on;
126-
keepalive.keepalivetime=idle*1000;
127-
keepalive.keepaliveinterval=intvl*1000;
128-
/* On Windows Vista and later, the number of keep-alive probes
129-
* (data retransmissions) is set to 10 and cannot be changed.
130-
* On Windows Server 2003, Windows XP, and Windows 2000, the default setting
131-
* for number of keep-alive probes is 5 and cannot be changed programmatically.
132-
*/
133-
DWORDdummy;
134-
if (WSAIoctl(socket,
135-
SIO_KEEPALIVE_VALS,
136-
(LPVOID) &keepalive,
137-
sizeofkeepalive,
138-
NULL,
139-
0,
140-
&dummy,
141-
NULL,
142-
NULL) ==-1)
67+
if (setsockopt(socket,
68+
IPPROTO_TCP,
69+
TCP_KEEPALIVE,
70+
(constchar*)&delay,
71+
sizeofdelay) ==-1) {
14372
returnWSAGetLastError();
73+
}
14474

14575
return0;
14676
}
@@ -202,7 +132,7 @@ static int uv__tcp_set_socket(uv_loop_t* loop,
202132

203133
/* TODO: Use stored delay. */
204134
if (handle->flags&UV_HANDLE_TCP_KEEPALIVE) {
205-
err=uv__tcp_keepalive(handle, socket, 1, 60, 1, 10);
135+
err=uv__tcp_keepalive(handle, socket, 1, 60);
206136
if (err)
207137
returnerr;
208138
}
@@ -819,6 +749,20 @@ static int uv__is_loopback(const struct sockaddr_storage* storage) {
819749
return0;
820750
}
821751

752+
// Check if Windows version is 10.0.16299 or later
753+
staticintuv__is_fast_loopback_fail_supported(void) {
754+
OSVERSIONINFOWos_info;
755+
if (!pRtlGetVersion)
756+
return0;
757+
pRtlGetVersion(&os_info);
758+
if (os_info.dwMajorVersion<10)
759+
return0;
760+
if (os_info.dwMajorVersion>10)
761+
return1;
762+
if (os_info.dwMinorVersion>0)
763+
return1;
764+
returnos_info.dwBuildNumber >= 16299;
765+
}
822766

823767
staticintuv__tcp_try_connect(uv_connect_t*req,
824768
uv_tcp_t*handle,
@@ -865,7 +809,7 @@ static int uv__tcp_try_connect(uv_connect_t* req,
865809
* is not reachable, instead of waiting for 2s. We do not care if this fails.
866810
* This only works on Windows version 10.0.16299 and later.
867811
*/
868-
if (uv__windows10_version1709() &&uv__is_loopback(&converted)) {
812+
if (uv__is_fast_loopback_fail_supported() &&uv__is_loopback(&converted)) {
869813
memset(&retransmit_ioctl, 0, sizeof(retransmit_ioctl));
870814
retransmit_ioctl.Rtt=TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS;
871815
retransmit_ioctl.MaxSynRetransmissions=TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS;
@@ -1391,30 +1335,22 @@ int uv_tcp_nodelay(uv_tcp_t* handle, int enable) {
13911335
}
13921336

13931337

1394-
intuv_tcp_keepalive(uv_tcp_t*handle, inton, unsigned intidle) {
1395-
returnuv_tcp_keepalive_ex(handle, on, idle, 1, 10);
1396-
}
1397-
1398-
intuv_tcp_keepalive_ex(uv_tcp_t*handle,
1399-
inton,
1400-
unsigned intidle,
1401-
unsigned intintvl,
1402-
unsigned intcnt) {
1338+
intuv_tcp_keepalive(uv_tcp_t*handle, intenable, unsigned intdelay) {
14031339
interr;
14041340

14051341
if (handle->socket!=INVALID_SOCKET) {
1406-
err=uv__tcp_keepalive(handle, handle->socket, on, idle, intvl, cnt);
1342+
err=uv__tcp_keepalive(handle, handle->socket, enable, delay);
14071343
if (err)
14081344
returnuv_translate_sys_error(err);
14091345
}
14101346

1411-
if (on) {
1347+
if (enable) {
14121348
handle->flags |= UV_HANDLE_TCP_KEEPALIVE;
14131349
} else {
14141350
handle->flags &= ~UV_HANDLE_TCP_KEEPALIVE;
14151351
}
14161352

1417-
/* TODO: Store idle if handle->socket isn't created yet. */
1353+
/* TODO: Store delay if handle->socket isn't created yet. */
14181354

14191355
return0;
14201356
}

0 commit comments

Comments
 (0)