1
0
mirror of https://github.com/libuv/libuv synced 2025-03-28 21:13:16 +00:00

488 Commits

Author SHA1 Message Date
Anna Henningsen
843b64faf5
win: add ENABLE_VIRTUAL_TERMINAL_INPUT raw tty mode (#4688)
Windows provides the `ENABLE_VIRTUAL_TERMINAL_INPUT` flag for TTY input
streams as a companion flag to `ENABLE_VIRTUAL_TERMINAL_PROCESSING`,
which libuv is already setting for TTY output streams.

Setting this flag lets the terminal emulator perform some of the
processing that libuv already currently does for input events,
but most notably enables receiving control sequences that are
otherwise entirely unavailable, e.g. for bracketed paste
(which the Node.js readline implementation added basic support for
in https://github.com/nodejs/node/commit/87af913b66eab78088acfd).

libuv currently already provides translations for key events to
control sequences, i.e. what this mode is intended to provide,
but libuv does not and cannot translate all such events.
Since the control sequences differ from the ones that Windows
has chosen to standardize on, and applications may not be expecting
this change, this is opt-in for now (but ideally will be the default
behavior starting in libuv v2.x, should that ever happen).

Another downside of this change is that not all shells reset
this mode when an application exits. For example, when running a
Node.js program with this flag enabled inside of PowerShell in
Windows terminal, if the application exits while in raw TTY input mode,
neither the shell nor the terminal emulator reset this flag, rendering
the input stream unusable.

While there's general awareness of the problem that console state is
global state rather than per-process (same as on UNIX platforms),
it seems that applications like PowerShell aren't expecting to need to
unset this flag on the input stream, only its output counterpart
(e.g. 4e7942135f/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs (L1156)).

Hence, `uv_tty_reset_mode()` is extended to reset the terminal
to its original state if the new mode is being used.

Refs: 87af913b66
Refs: https://github.com/microsoft/terminal/issues/4954
2025-02-21 23:34:53 +01:00
Hüseyin Açacak
82cdfb75ff win: fix the inconsistency in volume serial number 2025-02-17 08:35:37 +01:00
Rafael Gonzaga
e59e2a9e49
src: set a default thread name for workers (#4664) 2025-01-08 13:58:28 +01:00
Jameson Nash
72d9abccd7
win,fs: get (most) fstat when no permission (#4566)
Replaces: https://github.com/libuv/libuv/pull/4504
Fixes: https://github.com/libuv/libuv/issues/1980
Fixes: https://github.com/libuv/libuv/issues/3267

Co-authored-by: Hüseyin Açacak <huseyin@janeasystems.com>
2024-12-12 15:05:53 -05:00
Santiago Gimeno
61c966cf0b
src: add uv_thread_set/getname() methods (#4599)
`uv_thread_setname()` sets the name of the current thread. Different
platforms define different limits on the max number of characters
a thread name can be: Linux, IBMi (16), macOS (64), Windows (32767),
and NetBSD (32), etc. `uv_thread_setname()` will truncate it in case
`name` is larger than the limit of the platform.

`uv_thread_getname()` gets the name of the thread specified by `tid`.
The thread name is copied into the buffer pointed to by `name`. The
`size` parameter specifies the size of the buffer pointed to by `name`.
The buffer should be large enough to hold the name of the thread plus
the trailing NUL, or it will be truncated to fit.
2024-11-27 12:52:18 +01:00
Juan José
556a0f1f0f
unix,win: add support for detached threads (#4621)
This commit introduces the `uv_thread_detach` for thread detaching,
allowing threads to be detached state on both UNIX and Windows platforms.

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-11-26 08:44:38 -05:00
Ben Noordhuis
c6b67af390
unix,win: fix off-by-one in uv_wtf8_to_utf16() (#4609)
uv_wtf8_length_as_utf16() checks if codepoints are > 0xFFFF (to see if
it should be encoded as a surrogate pair), therefore uv_wtf8_to_utf16()
should too. Instead it checked > 0x1000. Harmonize the checks.

Fixes: https://github.com/nodejs/node/issues/55914
2024-11-19 19:09:03 +01:00
Hüseyin Açacak
1cbffcbd5d win,fs: fix bug in fs__readdir 2024-10-04 13:33:22 +02:00
Ben Noordhuis
9dddebab0d
test: delete test with invalid assumption (#4530)
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: https://github.com/libuv/libuv/issues/4368
2024-09-12 22:19:10 +02:00
Ben Noordhuis
1eac3310ad
linux: support abstract unix socket autobinding (#4499)
Autobinding is a feature that lets the kernel pick a name for the
abstract socket, instead of userspace having to provide one.

Two bugs that this change exposed are also fixed:

1. strlen(sa.sun_path) can read past the end if the file path is exactly
   sizeof(sa.sun_path) long (use memchr instead), and

2. don't return UV_ENOBUFS for abstract sockets when the buffer is
   exactly large enough to hold the result; per commit e5f4b79809,
   abstract socket names are not zero-terminated
2024-08-10 21:04:09 +02:00
Santiago Gimeno
badecdca14
fsevents: detect watched directory removal (#4376)
Which was broken both in `windows` and `macos`.
2024-07-30 00:59:38 +02:00
Ian Butterworth
18266a6969
win,fs: use posix delete semantics, if supported (#4318)
Implements posix delete for files and dirs, with fallback to the old
method if not supported (e.g. Fat32 or Win8).

Fixes: #3839
2024-07-29 17:38:26 -04:00
Andy Pan
ba24986f8d
unix: support SO_REUSEPORT with load balancing for UDP (#4419)
Signed-off-by: Andy Pan <i@andypan.me>
2024-06-20 17:17:17 +02:00
Andy Pan
d2d92b74a8
unix: support SO_REUSEPORT with load balancing for TCP 2024-05-21 13:36:49 +02:00
Ben Noordhuis
3ecce91410
linux: don't delay EPOLL_CTL_DEL operations (#4328)
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: https://github.com/libuv/libuv/issues/4323
2024-03-21 09:23:08 +01:00
Brad King
3f7191e5c2
win/spawn: optionally run executable paths with no file extension (#4292)
Add a process options flag to enable the optional behavior. Most users
are likely recommended to set this flag by default, but it was deemed
potentially breaking to set it by default in libuv.

Co-authored-by: Kyle Edwards <kyle.edwards@kitware.com>
2024-02-05 11:04:05 -05:00
Matheus Izvekov
51a22f60d6
unix,win: fix busy loop with zero timeout timers (#4250)
Calling `uv_timer_start(h, cb, 0, 0)` from a timer callback resulted in
the timer running immediately because it was inserted at the front of
the timer heap.

If the callback did that every time, libuv would effectively busy-loop
in `uv__run_timers()` and never make forward progress.

Work around that by collecting all expired timers into a queue and only
running their callback afterwards.

Fixes: https://github.com/libuv/libuv/issues/4245
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
2023-12-22 12:40:50 +01:00
Hao Hu
e135dfe183
unix,win: utility for setting priority for thread (#4075)
Add uv_thread_setpriority for setting priority for threads created by
uv_thread_create. Add uv_thread_getpriority for getting thread priority.

For Linux by default, if the scheduling policy is SCHED_OTHER and the
priority is 0, we need to set the nice value.

Fixes: https://github.com/libuv/libuv/issues/4051
2023-11-14 11:30:46 +01:00
SmorkalovG
2a4cab70ef
unix: reset signal counters after fork (#3485)
If a signal was received but was not dispatched before fork then
caught_signals counter should be reset. Closing of signal pipe makes
impossible to receive the signal that was counted.
There is no need in this signal because it was sent to parent process

Fixes: https://github.com/libuv/libuv/issues/3483
2023-09-29 12:54:35 +02:00
Kyle Edwards
c97017dd1d
win,spawn: allow %PATH% to be unset (#4116)
Fix: https://github.com/libuv/libuv/issues/4115
2023-08-14 15:25:11 -04:00
Ben Noordhuis
e893cd6826
unix: set ipv6 scope id for link-local addresses (#4107)
Link-local addresses (prefix fe80::/64) don't route unless you specify
the network interface to use so make libuv do that.

Fixes: https://github.com/nodejs/node/issues/48846
2023-08-03 22:18:50 +02:00
Ben Noordhuis
55376b044b
test: enable disabled spawn_same_stdout_stderr (#4105)
This test was added in commit e403a2c486 from 2014 but its author forgot
to enable it.
2023-07-25 16:48:22 +02:00
Ben Noordhuis
9c1de6e93f
test: enable disabled fs_link (#4104)
This test was added in commit 060026ced from 2011 but its author forgot
to actually enable it.
2023-07-25 16:48:04 +02:00
Ben Noordhuis
49d83c0301
test: enable disabled tcp_connect6_error_fault (#4103)
The test was added in commit e3f2631127 from 2011 but it appears the
author forgot to add it to the test list.

The other test from that commit was enabled by yours truly in 2012 in
7447048981 but apparently I overlooked the second test as well.
2023-07-25 15:58:08 +02:00
Trevor Norris
6df5a72151
test: add uv_cancel test for threadpool (#4065 2/2)
Check that uv_cancel() returns UV_EBUSY when called while the uv_work_cb
is being executed.
2023-06-21 11:31:44 -06:00
Trevor Norris
24d1d0802d
src: don't run timers if loop is stopped/unref'd (#4048)
The initial run of timers shouldn't happen if uv_stop() has been run
before uv_run() was called, and for backwards compatibility they also
shouldn't run if they have been unref'd before calling uv_run().
2023-06-16 11:00:06 -06:00
Ben Noordhuis
2f1614b128
unix,win: add UV_PIPE_NO_TRUNCATE flag (#4040)
Libuv's default behavior is to truncate long Unix socket paths. The flag
tells it to return an error instead.

Fixes: https://github.com/libuv/libuv/issues/4036
2023-06-06 17:08:36 +02:00
Stefan Karpinski
8f32a14afa
fs: use WTF-8 on Windows (#2970)
This allows working with valid filenames that are not well-formed
UTF-16. This is a superset of UTF-8, which does not error when it
encounters an unpaired surrogate but simply allows it.

Fixes: https://github.com/libuv/libuv/issues/2048
Refs: https://simonsapin.github.io/wtf-8/
Replaces: https://github.com/libuv/libuv/pull/2192 by Nikolai Vavilov <vvnicholas@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2023-05-23 10:25:38 -04:00
Santiago Gimeno
07261493a7 Revert "win: implement uv_try_write() for pipes(#3825 1/2)"
This reverts commit 244e0e20592f40fce87d573c9f7b6ff7f189c382.

For some reason this is breaking node.js IPC. I plan to investigate it
but we can let this for the next release.t

PR-URL: https://github.com/libuv/libuv/pull/4003
2023-05-19 11:08:49 +02:00
Santiago Gimeno
30fc896cc1
unix: handle CQ overflow in iou ring (#3991)
When there are more than 128 concurrent cq completions the CQ ring
overflows as signaled via the `UV__IORING_SQ_CQ_OVERFLOW`. If this
happens we have to enter the kernel to get the remaining items.
2023-05-15 10:42:14 +02:00
Ben Noordhuis
c8a1e6132b
unix,win: add uv_clock_gettime() (#3971)
Fixes: https://github.com/libuv/libuv/issues/1674
2023-04-27 22:13:46 +02:00
Trevor Norris
e02642cf3b src: fix events/events_waiting metrics counter (#3957)
The worker pool calls all callbacks locally within the queue. So the
value of nevents doesn't properly reflect that case. Increase the number
of events directly from the worker pool's callback to correct this.

In order to properly determine if the events_waiting counter needs to be
incremented, store the timeout value at the time the event provider was
called.
2023-04-24 15:29:14 -06:00
Trevor Norris
6600954906
win,unix: change execution order of timers (#3927)
The maximum number of times timers should run when uv_run() is called
with UV_RUN_ONCE and UV_RUN_NOWAIT is 1. Do that by conditionally
calling timers before entering the while loop when called with
UV_RUN_DEFAULT.

The reason to always run timers at the end of the while loop, instead of
at the beginning, is to help enforce the conceptual event loop model.
Which starts when entering the event provider (e.g. calling poll).

Other than only allowing timers to be processed once per uv_run()
execution, the only other noticeable change this will show is if all the
following are true:
* uv_run() is called with UV_RUN_NOWAIT or UV_RUN_ONCE.
* An event is waiting to be received when poll is called.
* Execution time between the call to uv_timer_start() and entering the
  while loop is longer than the timeout.

If all these are true, then timers that would have executed before
entering the event provider will now be executed afterward.

Fixes: https://github.com/libuv/libuv/issues/3686
Co-authored-by: Momtchil Momtchev <momtchil@momtchev.com>
2023-03-20 10:04:57 -06:00
Jameson Nash
2f110a50df
misc: extend getpw to take uid as an argument (#3523)
File system operations may return uid and gid values, which we may want
to pretty-print. We already have the code for getting information for
the current user, so just need to add a parameter to make it exposed for
every user. We expose information about groups in a similar manner also.
2023-01-17 21:51:28 -06:00
Ben Noordhuis
244e0e2059 win: implement uv_try_write() for pipes(#3825 1/2) 2022-12-01 23:16:58 +01:00
Stefan Stojanovic
c17bd99f1c
win: fix fstat for pipes and character files (#3811)
Calling uv_fs_fstat for file types other then disk type was resulting in
error on Windows while it was retrieving data on Linux. This change
enables getting fstat for pipes and character files on Windows with data
fetched being as reasonable as possible.

A simple test is also added to check this behavior on all platforms. It
uses stdin, stdout and stderr. uv_fs_fstat needs to pass with disk files
pipes and character files (eg. console).

Refs: https://github.com/nodejs/node/issues/40006
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2022-11-29 17:46:09 -05:00
Trevor Norris
e141586053
src: add new metrics APIs (#3749)
The following metrics are now always recorded and available via the new
uv_metrics_info() API.

* loop_count: Number of event loop iterations.
* events: Total number of events processed by the event handler.
* events_waiting: Total number of events waiting in the event queue when
  the event provider request was made.

Benchmarking has shown no noticeable impact recording these metrics.

PR-URL: https://github.com/libuv/libuv/pull/3749
2022-11-11 16:21:58 +01:00
Santiago Gimeno
3706c4f855 win,pipe: fixes in uv_pipe_connect()
Make unices and windows consistent when closing a pipe while it's
connecting so they all return `UV_ECANCELED`.

Avoid race condition between `pipe_connect_thread_proc()` and `uv_close()` when
accessing `handle->name`.

Fixes: https://github.com/libuv/libuv/issues/3578
2022-11-11 10:44:34 +01:00
ywave620
dff3f8ccab
win: optimize udp receive performance (#3807)
Do at most 32 nonblocking udp receive in a row.

Fixes: https://github.com/libuv/libuv/issues/3704
2022-11-08 10:23:40 +01:00
daomingq
e900006642
thread: add support for affinity (#3774)
Backported thread affinity feature and related dependency commits
from master. It will add support for those APIs: uv_cpumask_size,
uv_thread_setaffinity, uv_thread_getaffinity.
The supported platforms are Linux, Freebsd, and Windows.
Empty implementations (returning UV_ENOTSUP) on non-supported platforms
(such as OS X and AIX).
2022-10-21 09:18:10 -04:00
ywave620
3e7d2a6492
stream: process more than one write req per loop tick (#3728)
Fixes: https://github.com/libuv/libuv/issues/3668
2022-10-08 10:23:01 +02:00
Ben Noordhuis
b00d1bd225
unix,win: fix memory leak in uv_fs_scandir() (#3760)
uv_fs_scandir() leaked an entry when you called it on a directory with
a single entry _and_ you didn't run the iterator until UV_EOF.

Fixes: https://github.com/libuv/libuv/issues/3748
2022-09-22 09:25:55 +02:00
Stacey Marshall
f5e4d85cd2
unix,tcp: allow EINVAL errno from setsockopt in uv_tcp_close_reset() (#3662)
Some setsockopt() implememantations may return with errno of EINVAL
when the socket has been shut down already, as documented in the
Open Group Specifications Issue 7, 2018.

When this happens, reset errno and continue to mark the socket closed
and handle any callback.
2022-07-11 12:29:25 -04:00
theanarkh
8bcd689c04
tcp,pipe: fail bind or listen after close (#3641)
Return `UV_EINVAL` in `bind` and `listen` when `handle` is
`UV_HANDLE_CLOSING` or `UV_HANDLE_CLOSED`.

Fixes: https://github.com/libuv/libuv/issues/3503
2022-06-11 00:32:08 -04:00
Ben Noordhuis
7825bfb49d
test: remove disabled callback_order test (#3619)
This test has always been disabled for the 10 years of its existence and
there are other tests that exercise "what happens when" event ordering.

Fixes: https://github.com/libuv/libuv/issues/3618
2022-05-09 09:17:35 +02:00
Jameson Nash
7c9b3938df
macos: avoid posix_spawnp() cwd bug (#3597)
macOS 10.15 has a bug where configuring the working directory with
posix_spawn_file_actions_addchdir_np() makes posix_spawnp() fail with
ENOENT even though the executable is spawned successfully.

Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
2022-04-15 14:10:27 -04:00
Andy Fiddaman
612c28b89f
sunos: fs-event callback can be called after uv_close() (#3542)
On illumos and Solaris, fs events are implemented with
PORT_SOURCE_FILE type event ports. These are one-shot so
need re-arming each time they fire. Once they are armed
and an event occurs, the kernel removes them from the current
cache list and puts them on an event queue to be read by
the application.

There's a window in closing one of these ports when it could
have triggered and be pending delivery. In that case, the
attempt to disarm (dissociate) the event will fail with ENOENT
but libuv still goes ahead and closes down the handle. In
particular, the close callback (uv_close() argument) will be
called but then the event will subsequently be delivered if
the loop is still active; this should not happen.
2022-04-11 11:25:59 -04:00
twosee
69ebb2d720
win: fix unexpected ECONNRESET error on TCP socket (#3584) 2022-04-07 21:44:45 -04:00
Ben Noordhuis
1fe609ea05
unix,win: fix UV_RUN_ONCE + uv_idle_stop loop hang (#3590)
Wrong accounting of idle handles in uv_run() made it sleep when there
was nothing left to do. Do a non-blocking poll for I/O instead.
2022-04-06 15:49:21 +02:00
Guilherme Íscaro
2a31fe8552
core: add thread-safe strtok implementation (#3553)
This commit adds the support for a custom strtok implementation, which
is reentrant. On some systems strtok_r or strstep is available for that
purpose; however, since these are an extension, it is difficult to
control if it will be available on every supported system.
2022-03-22 15:15:00 -04:00