Skip to content

[pull] v1.x from libuv:v1.x #190

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

Open
wants to merge 753 commits into
base: v1.x
Choose a base branch
from
Open

[pull] v1.x from libuv:v1.x #190

wants to merge 753 commits into from

Conversation

pull[bot]
Copy link

@pull pull bot commented Apr 28, 2021

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

* fix: always zero-terminate idna output

* fix: reject zero-length idna inputs

* test: empty strings are not valid IDNA

---------

Co-authored-by: Santiago Gimeno <[email protected]>
santigimeno and others added 26 commits February 7, 2024 20:20
Changes since version 1.47.0:

* misc: remove deprecated stalebot file (Jameson Nash)

* build: disable windows asan buildbot (Ben Noordhuis)

* test: don't run tcp_writealot under msan (Ben Noordhuis)

* build,win: remove extraneous -lshell32 (Ben Noordhuis)

* unix: ignore ifaddrs with NULL ifa_addr (Stephen Gallagher)

* unix,win: utility for setting priority for thread (Hao Hu)

* pipe: add back error handling to connect / bind (Jameson Nash)

* test: check if ipv6 link-local traffic is routable (Ben Noordhuis)

* win: remove check for UV_PIPE_NO_TRUNCATE (Jameson Nash)

* linux: disable io_uring on hppa below kernel 6.1.51 (matoro)

* unix,win: fix read past end of pipe name buffer (Ben Noordhuis)

* unix: unbreak macOS < 10.14 (Sergey Fedorov)

* aix: disable ipv6 link local (Abdirahim Musse)

* doc: move cjihrig to emeriti (cjihrig)

* unix: correct pwritev conditional (Bo Anderson)

* test_fs.c: Fix issue on 32-bit systems using btrfs (Stephen Gallagher)

* misc: ignore libuv-release-tool files (Jameson Nash)

* win: honor NoDefaultCurrentDirectoryInExePath env var (Ardi Nugraha)

* idna: fix compilation warning (Saúl Ibarra Corretgé)

* linux: remove HAVE_IFADDRS_H macro (Ben Noordhuis)

* test: skip tcp-write-in-a-row on IBM i (Abdirahim Musse)

* build,win: work around missing uuid.dll on MinGW (Anton Bachin)

* win: stop using deprecated names (Matheus Izvekov)

* unix,win: fix busy loop with zero timeout timers (Matheus Izvekov)

* aix,ibmi: use uv_interface_addresses instead of getifaddrs (Abdirahim
  Musse)

* linux: fix bind/connect for abstract sockets (Santiago Gimeno)

* win: replace c99 comments with c89 comments (Trevor Flynn)

* build: add .cache clangd folder to .gitignore (Juan José Arboleda)

* unix: support full TCP keep-alive on Solaris (Andy Pan)

* freebsd: fix F_KINFO file path handling (David Carlier)

* linux: retry fs op if unsupported by io_uring (Santiago Gimeno)

* freebsd: fix build on non-intel archs (David Carlier)

* unix: optimize uv__tcp_keepalive cpp directives (Andy Pan)

* linux: disable io_uring on ppc64 and ppc64le (Brad King)

* doc: add very basic Security Policy document (Santiago Gimeno)

* build: re-enable msvc-asan job on CI (Jameson Nash)

* win/spawn: optionally run executable paths with no file extension
  (Brad King)

* win: fix ESRCH implementation (Jameson Nash)

* unix,win: reset the timer queue on stop (Santiago Gimeno)

* fix: always zero-terminate idna output (Ben Noordhuis)

* fix: reject zero-length idna inputs (Ben Noordhuis)

* test: empty strings are not valid IDNA (Santiago Gimeno)

* Merge pull request from GHSA-f74f-cvh7-c6q6 (Ben Noordhuis)
The return value from signal(2) is a pointer. Use the right macro.
It's been reported that creating many event loops introduces measurable
overhead now that libuv creates an sqpoll-enabled ring.

I don't really see any change in CPU time with or without this change
but deferring ring creation until it's actually used seems like a good
idea, and comes with no downsides that I can think of, so let's do it.

Fixes: #4308
uv_available_parallelism does not handle container cpu limit
set by systems like Docker or Kubernetes. This patch fixes
this limitation by comparing the amount of available cpus
returned by syscall with the quota of cpus available defined
in the cgroup.

Fixes: #4146
Issue:
1. uv__io_poll calls uv__udp_io with revents == POLLIN + POLLOUT
2. uv__udp_io calls your recv_cb
3. you close the handle in callback
4. uv__udp_io calls uv__udp_sendmsg
5. uv__udp_sendmsg calls uv__io_feed
6. kaboom!
According to the documentation for Cygwin, the penultimate field
of /proc/pid/stat corresponds to the RSS, so the method is basically
the same as in the Linux version. The only difference is that getpagesize()
will return wincap.allocation_granularity(), but in this mapping, RSS is
calculated using wincap.page_size(), which can be accessed by sysinfo.mem_unit.
It might happen that only using `WaitForSingleObject()` with timeout 0
could return WAIT_TIMEOUT as the process might not have been signaled
yet. To improve things, first use `GetExitCodeProcess()` and check
that `status` is not `STILL_ACTIVE`. Then, to cover for the case that the exit
code was actually `STILL_ACTIVE` use `WaitForSingleObject()`. This could
still be prone to the race condition but only for that case.
The test hits an honest-to-$deity compiler runtime bug, see the
investigation in the linked issue.

Fixes: #4338
Make sure we allocate the memory with uv__malloc so it's in turn freed
with uv__free.

Fixes: #4329
- The filename of the executable may contain both spaces and parentheses
- Use uv__slurp instead of open/read/close
The kernel that ships with the new Ubuntu 22.04 CI image seems to have a
PIE slide that is bigger than the sanitizer runtimes can handle.

It makes ASan fail with thousands of "AddressSanitizer:DEADLYSIGNAL"
warnings, and MSan error with complaints about memory accesses outside
known ranges. Disabling address space layout randomization fixes both.

This commit also fixes a small bug in the platform_output test where
the cgroups v1 logic did not handle the "unlimited quota" special case
properly. Ubuntu 20.04 still uses cgroups v1.
Remove it since it can cause stack overflows. Use heap allocation
instead.

Fixes: #4348
I removed the fallback code back in October but it prevents Node.js
from upgrading libuv in their v20.x release line because they support
systems older than we do. Bring back a dlsym-based fallback path.

Fixes: #4332
Perform EPOLL_CTL_DEL immediately instead of going through
io_uring's submit queue, otherwise the file descriptor may
be closed by the time the kernel starts the operation.

Fixes: #4323
* win: simplify uv_once implementation

InitOnceExecuteOnce is available in Windows >= Vista.

Ref: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initonceexecuteonce
uv_udp_init() creates the UDP socket lazily but to set socket options
there must be, well, a socket to set the options on. Document how and
when that requirement is met.

Fixes: #4370
Benchmarking shows that sendmsg() is persistently around 1% faster for
single datagrams, and that kind of stands to reason because there is
less setup overhead, and the kernel has to copy in less data.

Fixes: #4320
The file descriptor leak in the inner path was pointed out by @theanarkh
and I subsequently spotted another one in the outer loop. Rewrite the
function to process all control messages.

Refs: #4357
juanarbol and others added 30 commits May 10, 2025 10:04
The documentation is referring to an internal name -
UV_LOOP_ENABLE_IO_URING_SQPOLL - in several places. Fix this by using
the public UV_LOOP_USE_IO_URING_SQPOLL name instead.
pthread_getschedparam and pthread_setschedparam do not use errno but
instead return the error code directly.

https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_getschedparam.html

Also include a fix to return UV_ESRCH instead of UV_EBADF on Windows,
like Unix systems do.
The link at gnu.org is a redirect now and the docs linter breaks some times.
Implement `uv_tcp_keepalive_ex` function that extends
`uv_tcp_keepalive` to support `TCP_KEEPINTVL` and `TCP_KEEPCN`
socket options in addition to TCP_KEEPIDLE.
This mirrors the behavior already fixed in the CMake build system.

Fixes: #4794
Refs: 4681d5d
Signed-off-by: Juan José Arboleda <[email protected]>
These macros are not defined in the public headers

Signed-off-by: Juan José Arboleda <[email protected]>
Distinguish between errors and "the console title is the empty string"
when calling GetConsoleTitle. Both are signified by a return value of
zero.

No test because I couldn't think of a succinct way to programmatically
create a new console window with an empty title.

Fixes: nodejs/node#58695
Resolves a potential race condition when a child process has been
created between WSASocketW() and SendHandleInformationW().
Refs: #4755
Signed-off-by: Juan José Arboleda <[email protected]>
uv_set_process_title loads and unloads a bunch of dynamic libraries,
and that's quite slow and prone to time out when running concurrently
under AddressSanitizer.
Commit 7fb43d3 from August 2012 moved uv__atomic_exchange_set from
async.c into a header file but in all those years, nothing except
async.c has ever used it. Move the function back again and remove
the header file.

I removed the superfluous uses of inline/INLINE but this is otherwise
a non-functional change.

Refs: #4819
Large-ish functions with many call sites in different translation units
should not be `static inline`, that just results in lots of code
duplication which the linker may or may not deduplicate. When it does,
the linker has to do extra work; when it doesn't, binaries get bigger.

Refs: #4819
Switch to __sync_fetch_and_or on x86. Libuv already uses it on other
architectures.
Starting a new read after uv_read_cb returns causes memory corruption on
the OVERLAPPED read_req if uv_read_stop+uv_read_start was called during
the callback after the latest refactoring. This apparently also forces
the kernel to deadlock us, since it apparently cannot cancel the second
read while the first one is pending (reads apparently are not permitted
to finish out of order). Avoid that simply by not issuing another read
(set more=0) if there is already a read pending (from uv_read_start).

There are probably better things we could do here (such as bring back
`uv_active_tcp_streams_threshold`), but the current `alloc_cb` design
may not currently permit that without making breaking changes. We could
also detect in `uv_read_start` that we are inside of of the `read_cb`
for that stream, and defer the actual zero-read until the read_cb
returns, but that would likely be a larger change.

Fix #4738
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.