Skip to content

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

Open
pull[bot] wants to merge 834 commits intobazelregistry:v1.xfrom
libuv:v1.x
Open

[pull] v1.x from libuv:v1.x#190
pull[bot] wants to merge 834 commits intobazelregistry:v1.xfrom
libuv:v1.x

Conversation

@pull
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 : )

haoyu234 and others added 27 commits August 15, 2024 11:01
In #4470, I accidentally copied the bug from unix, where calling
uv_stream_set_blocking can cause the whole process to hang on a read.
However, unlike unix, where libuv attempts to set the O_NONBLOCK flag in
uv_pipe_open (as long as the handle never gets passed to uv_spawn), the
NT kernel is not capable of enabling OVERLAPPED operation later (but
fortunately, it also cannot disable it later too).

This implementation might be good to copy to unix (using FIONREAD) to
address the same bug that happens there if the user has called uv_spawn
or uv_stream_set_non_blocking on this handle in the past.
Use GetProcessAffinityMask() to estimate the available parallelism.
Before this commit, it simply used the number of available CPUs.

Fixes: #4520
Get parent process ID using NtQueryInformationProcess, it's faster than
using CreateToolhelp32Snapshot.
Fixes commit 58dfb6c from a few days ago. DWORD_PTR is 32 bits on
x86 Windows. Use the right bit count when checking the population count.

Interestingly enough, it manifested itself as double counting online
processors, presumably because the compiler emits a ROR instead of SHR.

Fixes: #4524
Yet another followup to #4511. The functional/legacy/increment_spec.lua
test failed most of the time without this, and passes consistently with
it. It seemed unexpected this code path gets reached (perhaps imply
that the user wrote zero bytes?), but good to fix of course.
Follows up on #659.

Signed-off-by: Andy Pan <i@andypan.me>
Libuv stores the `struct termios` for use inside uv_tty_reset_mode().

Node.js uses said function to restore the tty to its original mode
on SIGINT or SIGTERM, when there is no opportunity to shut down the
process normally.

Track uv_tty_t handle closing, otherwise we might be trying to use a
stale termios.

The current solution is not ideal because there can be multiple handles
that refer to the same tty/pty and, for various reasons, we can't really
determine when we close the last handle. The last handle may not even be
inside the current process.

Still, all things considered, it's probably (hopefully!) an improvement
over the status quo.

Refs: #4398
Delete the fs_event_error_reporting test. It fails in different ways,
most frequently on the TSan sanitizer buildbot, due to running out of
file descriptors when that is not expected, or vice versa, *not*
running out of file descriptors when that *is* expected.

The test creates a large number of event loops and expects to,
eventually, hit EMFILE but it sometimes hits it too early, and
sometimes not at all.

I don't think TSan is really responsible here, it just makes the
invalid assumption in the test itself more visible.

Fixes: #4368
Fixes: #4533
Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
Both gcc 11 and 12 emit wrong code for a function call pointer in one
very specific context.

Fixes: #4532
Changes since version 1.48.0:

* test: fix -Wpointer-to-int-cast on 32 bits systems (Ben Noordhuis)

* build: add alias for libuv to CMakeLists.txt (Anthony Alayo)

* linux: create io_uring sqpoll ring lazily (Ben Noordhuis)

* misc: run sample CI when code changes (Jameson Nash)

* linux: fix uv_available_parallelism using cgroup (Thomas Walter)

* doc: fix tty example segfault (hiiizxf)

* udp,unix: fix sendmsg use-after-free (Geddy)

* cygwin: implement uv_resident_set_memory (Farzin Monsef)

* win: almost fix race detecting ESRCH in uv_kill (Santiago Gimeno)

* test: disable env var test under win32+asan (Ben Noordhuis)

* unix,fs: fix realpath calls that use the system allocator (Saúl Ibarra
  Corretgé)

* sunos: sync tcp keep-alive with other unices (Andy Pan)

* linux: fix /proc/self/stat executable name parsing (Farzin Monsef)

* test,ci: fix [AM]San, disable ASLR (Ben Noordhuis)

* win: remove _alloca usage (Ben Noordhuis)

* unix: reinstate preadv/pwritev fallback code (Ben Noordhuis)

* linux: don't delay EPOLL_CTL_DEL operations (Ben Noordhuis)

* doc: fix typos in ChangeLog (tgolang)

* unix,win: error on zero delay tcp keepalive (Saúl Ibarra Corretgé)

* win: simplify uv_once implementation (Saúl Ibarra Corretgé)

* doc: correct udp socket options documentation (Ben Noordhuis)

* linux: don't use sendmmsg() for single datagrams (Ben Noordhuis)

* unix: fix fd leaks in SCM_RIGHTS error path (Ben Noordhuis)

* win: robustify uv_os_getenv() error checking (Ben Noordhuis)

* test: use newer ASSERT_MEM_EQ macro (Ben Noordhuis)

* unix: de-duplicate conditions for using kqueue (Brad King)

* darwin: simplify uv_hrtime (Saúl Ibarra Corretgé)

* mailmap: update saghul's main email address (Saúl Ibarra Corretgé)

* win: remove no longer needed define (Saúl Ibarra Corretgé)

* doc: fix some typos (josedelinux)

* linux,darwin: make `uv_fs_copyfile` behaves like `cp -r` (Juan José
  Arboleda)

* dragonfly: disable SO_REUSEPORT for UDP socket bindings (Andy Pan)

* test: remove the obsolete HAVE_KQUEUE macro (Andy Pan)

* unix: use the presence of SOCK_* instead of OS macros for socketpair
  (Andy Pan)

* bsd: support pipe2() on *BSD (Andy Pan)

* unix: support SO_REUSEPORT with load balancing for TCP (Andy Pan)

* doc: add entries for extended getpw (Juan José Arboleda)

* test: fix the flaky test-tcp-reuseport (Andy Pan)

* aix,ibmi: fix compilation errors in fs_copyfile (Jeffrey H. Johnson)

* unix: support SO_REUSEPORT with load balancing for UDP (Andy Pan)

* tcpkeepalive: distinguish OS versions and use proper time units (Andy
  Pan)

* win: map ERROR_BAD_EXE_FORMAT to UV_EFTYPE (Hüseyin Açacak)

* doc: add instruction how to install with Conan (Uilian Ries)

* unix,win: remove unused req parameter from macros (Viacheslav
  Muravyev)

* build: fix android ci build (Ben Noordhuis)

* unix,win: export wtf8 functions properly (Ben Noordhuis)

* hurd: add includes and macro prerequisites (Olivier Valentin)

* hurd: stub uv_thread_setpriority() (Olivier Valentin)

* ci: use macOS 12 for macOS and iOS builds (Saúl Ibarra Corretgé)

* darwin: fix crash on iOS(arm64) (郑苏波 (Super Zheng))

* Create dependabot.yml for updating github-actions (Jameson Nash)

* doc: correct names of Win32 APIs in fs.rst (zeertzjq)

* ci: bump upload and download-artifact versions (dependabot[bot])

* ci: bump actions/setup-python from 4 to 5 (dependabot[bot])

* ci: bump KyleMayes/install-llvm-action from 1 to 2 (dependabot[bot])

* win,error: remap ERROR_NO_DATA to EAGAIN (Jameson Nash)

* test: handle zero-length udp datagram (Ben Noordhuis)

* misc: remove splay trees macros (Viacheslav Muravyev)

* test,openbsd: remove superfluous ifdef guard (Ben Noordhuis)

* win,fs: use posix delete semantics, if supported (Ian Butterworth)

* win: fix env var in uv_os_homedir and uv_os_tmpdir (Hüseyin Açacak)

* fsevents: detect watched directory removal (Santiago Gimeno)

* ci: bump actions/checkout to 4 (dependabot[bot])

* linux: eliminate a read on eventfd per wakeup (Andy Pan)

* test: pipe_overlong_path handle ENAMETOOLONG (Abdirahim Musse)

* win,fs: use the new Windows fast stat API (Hüseyin Açacak)

* win,pipe: fix race with concurrent readers (Jameson Nash)

* win,signal: fix data race dispatching SIGWINCH (Jameson Nash)

* build: ubsan fixes (Matheus Izvekov)

* linux: disable SQPOLL io_uring by default (Santiago Gimeno)

* win: fix fs.c ubsan failure (Matheus Izvekov)

* test: rmdir can return `EEXIST` or `ENOTEMPTY` (Richard Lau)

* test: check for `UV_CHANGE` or `UV_RENAME` event (Richard Lau)

* unix,fs: silence -Wunused-result warning (Santiago Gimeno)

* linux: support abstract unix socket autobinding (Ben Noordhuis)

* kqueue: use EVFILT_USER for async if available (Andy Pan)

* win: remove deprecated GetVersionExW call (Shelley Vohr)

* doc: document uv_loop_option (握猫猫)

* doc: fix the `uv_*_set_data` series of functions (握猫猫)

* doc: properly label enumerations and types (握猫猫)

* doc: document specific macOS fs_event behavior (Santiago Gimeno)

* win,pipe: restore fallback handling for blocking pipes (Jameson Nash)

* unix,win: remove unused rb-tree macro parameters (Viacheslav Muravyev)

* win: compute parallelism from process cpu affinity (Ben Noordhuis)

* win: use NtQueryInformationProcess in uv_os_getppid (Zuohui Yang)

* win,pipe: fix missing assignment to success (Jameson Nash)

* win: fix uv_available_parallelism on win32 (Ben Noordhuis)

* win,pipe: fix another missing assignment to success (Jameson Nash)

* kqueue: disallow ill-suited file descriptor kinds (Andy Pan)

* unix: restore tty attributes on handle close (Ben Noordhuis)

* test: delete test with invalid assumption (Ben Noordhuis)

* dragonflybsd: fix compilation failure (Jeffrey H. Johnson)

* test: run android tests on ci (Edigleysson Silva (Edy))

* darwin: add udp mmsg support (Raihaan Shouhell)

* unix: work around arm-linux-gnueabihf-gcc bug (Ben Noordhuis)

* unix: expand uv_available_parallelism() to support more platforms
  (Ondřej Surý)

* doc: add known issue in armv7 (Santiago Gimeno)
Overlooked in commit 1c778bd ("darwin: add udp mmsg support") from
earlier this month.

Fixes: #4544
Introduced in Linux 6.6, it tells the kernel to omit the sqarray from
the ring buffer.

Libuv initalizes the array once to an identity mapping and then forgets
about it, so not only does it save a little memory (ca. 1 KiB per ring)
but it also makes things more efficient kernel-side because it removes
a level of indirection.
Route ftruncate() system calls through io_uring instead of the thread
pool when the kernel is new enough to support it (linux >= 6.9).

This commit harmonizes how libuv checks if the kernel is new enough.
Some ops were checking against `uv__kernel_version()` directly while
others stored the result of the version check as a feature flag.

Because the kernel version is cached, and because it is more direct
than a feature flag, I opted for the former approach.
Fixed incorrect verification of the pNtQueryDirectoryFile pointer.
louwers and others added 30 commits December 8, 2025 19:02
Add macos-15 runners. Remove the deprecated macos-13 runners.

Fixes: #4965
Refs: actions/runner-images#10924
And fix a stupid typo that made GHA skip running the tests 🤦
Use GetFileInformationByHandleEx(FileBasicInfo) instead of GetFileInformationByHandle() because it's cheaper -- one syscall, instead of two [1]

[1]: https://blog.axiorema.com/engineering/hidden-cost-getfileinformationbyhandle/
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](actions/download-artifact@v6...v7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Fix `threadpool_cancel_fs_iouring` so it takes `UV_FS_FTRUNCATE` into
account.
If uv_spawn() fails after uv__handle_init() has been called, the handle
remains in loop->handle_queue. This causes use-after-free if the handle
is stack-allocated or freed, and a subsequent loop operation like
uv_walk() accesses it.

This follows the same pattern as uv_tcp_init_ex() which explicitly
removes the handle from the queue on error.
As of January 1, 2026, HP-UX is well and truly dead. Remove it.
Zero the struct. The compiler is not aware it's not actually used.
Check the length before doing the compare like we do a few lines below,
not the other way around. It's a false positive because the length is
capped well below the maximum object size but it's an easy fix.

Fixes the following warning:

    test/test-poll-oob.c:94:19: warning: ‘strncmp’ specified bound
    [18446744071562067968, 18446744073709551615] exceeds maximum
    object size 9223372036854775807 [-Wstringop-overread]
AddressSanitizer was right to complain about the test because it was
passing an uninitialized `struct winsize` to openpty().
This adds support for "Linux"-style Windows symbolic links, reparse tag
0xA000001D (IO_REPARSE_TAG_LX_SYMLINK).
It was reported that PTYs on Linux sometimes report POLLHUP, return a
partial read, but still return more data on the next read.

Libuv contains an optimization where it assumes a partial read after
POLLHUP means the next read can be skipped because it's going to fail
with EOF anyway. That assumption was thought to be always true but,
alas, it isn't.

The fact the optimization has been present for 13 years and this is the
first bug report about it, indicates how rare this particular condition
is, but of course we can't skim on correctness.

The reworked optimization only uses POLLHUP as an input signal when
POLLIN is not also set. That means we no longer have to track partial
reads because we're going to try and read anyway as long as POLLIN is
set. It seems to cause no measurable regressions on the test suite or
the (lightly tested) benchmarks.

Fixes: #4992
The test is multi-threaded and expects both threads to receive at least
some of the incoming datagrams but there isn't always true parallelism
under QEMU's user-mode emulator.

Single-core systems are also susceptible to that so also add a check
that we have at least two cores to run on.

It's not perfect because a sufficiently dedicated test torturer could
probably concoct a containerized setup where the core count > 1 but the
available CPU slice is so small that the test effectively still runs
sequentially, but it's better than nothing.

Fixes: #4777
The test is multi-threaded and expects both threads to receive at least
some of the incoming connections but there isn't always true parallelism
under QEMU's user-mode emulator.

Single-core systems are also susceptible to that so also add a check
that we have at least two cores to run on.

As mentioned in the change for the udp_reuseport test from a few days
ago, the test is not perfect (there being > 1 core doesn't guarantee
we actually get to run on them) but it's better than nothing.

Fixes: #5003
Catch sign conversion bugs by introducing a bounds check that doubles
as a sanity check.

Fixes: #5012
Accomplish this by replacing `GetDiskFreeSpaceW()` with
`NtQueryVolumeInformationFile()` which allows us to represent blocks
larger than 2^32 - 1 via
`FILE_FS_FULL_SIZE_INFORMATION.TotalAllocationUnits`.

Expanded `fs_statfs` test to check that `uv_fs_statfs()` also works with
files, meaning #2683 remains fixed
without the need of #2695.
Sun Studio / Oracle Developer Studio hasn't had a release in almost
nine years. If Oracle doesn't feel like supporting it, then neither
do I.
0x10FFFF is the valid max unicode character, so the check should be
inclusive.

This assert gets triggered because uv__wtf8_decode1 (used by
uv_wtf8_length_as_utf16) has the correct code_point <= 0x10FFFF check,
so the sequence is treated as valid and it will be passed into
uv_wtf8_to_utf16, where the incorrect assert gets triggered:

src/idna.c:397: uv_wtf8_to_utf16: Assertion `code_point < 0x10FFFF' failed.
Apparently there is no openpty() on those platforms. Introduced in
commit 2e2114e from last month.

Fixes: #5018
Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
some users of libuv rely on uv_exepath to be an actual path to a
program. unfortunately, the OpenBSD KERN_PROC_ARGV sysctl just returns
what is in argv[0], so if the program was executed by being looked up in
$PATH, uv_exepath would only return the basename and not an actual path.

to fix, this use the same approach as IBM i, OS/390 and AIX by searching
with uv__search_path. this is also the same approach the Zig language
has taken for the similar selfExePath function for OpenBSD.

the tests expect that uv_exepath still works after uv_set_process_title,
which on BSD is a call to setproctitle. the place setproctitle stores to
is the same place that KERN_PROC_ARGV reads from, so we need to stash
the original argv[0] in uv_setup_args to recover it later in uv_exepath.
~~~
/Users/saghul/src/libuv/src/unix/udp.c:1460:26: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1460 |   struct sockaddr* addrs[N];
      |                          ^
/Users/saghul/src/libuv/src/unix/udp.c:1461:22: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1461 |   unsigned int nbufs[N];
      |                      ^
/Users/saghul/src/libuv/src/unix/udp.c:1462:18: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1462 |   uv_buf_t* bufs[N];
      |                  ^
3 warnings generated.
/Users/saghul/src/libuv/src/unix/udp.c:1460:26: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1460 |   struct sockaddr* addrs[N];
      |                          ^
/Users/saghul/src/libuv/src/unix/udp.c:1461:22: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1461 |   unsigned int nbufs[N];
      |                      ^
/Users/saghul/src/libuv/src/unix/udp.c:1462:18: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1462 |   uv_buf_t* bufs[N];
      |                  ^
~~~
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.