Commit Graph

1589 Commits

Author SHA1 Message Date
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
b60f08e782 test: add ASSERT_OK (#3957)
The majority of uses for ASSERT_EQ are to check if the return value is
0. So make a macro specifically for this and make things easier to read.
2023-04-24 15:29:14 -06:00
Ben Noordhuis
dfae365f84
linux: add IORING_OP_CLOSE support (#3964) 2023-04-20 10:44:16 +02:00
Ben Noordhuis
5ca5e475bb
linux: add IORING_OP_OPENAT support (#3963) 2023-04-20 10:17:06 +02:00
Ben Noordhuis
3ba75f1300
test: disable signal test under ASan and MSan (#3961)
The signal_multiple_loops test is flaky when run under AddressSanitizer
and MemorySanitizer. Sometimes thread creation fails, other times it
simply times out.

Fixes: https://github.com/libuv/libuv/issues/3956
2023-04-19 07:40:18 +02:00
Ben Noordhuis
d2c31f429b
linux: introduce io_uring support (#3952)
Add io_uring support for several asynchronous file operations:

- read, write
- fsync, fdatasync
- stat, fstat, lstat

io_uring is used when the kernel is new enough, otherwise libuv simply
falls back to the thread pool.

Performance looks great; an 8x increase in throughput has been observed.

This work was sponsored by ISC, the Internet Systems Consortium.

Fixes: https://github.com/libuv/libuv/issues/1947
2023-04-18 12:32:08 +02:00
Ben Noordhuis
cb5da59226
test: don't use static buffer for formatting (#3953)
Don't use a static buffer to hold human-readable "big" numbers.

The buffer isn't big enough for benchmarks like fs_stat that print a
large number of them. Have the caller pass in a buffer instead.
2023-04-14 16:54:28 +02: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
Trevor Norris
91a7e49846
test: silence more valgrind warnings (#3917)
Pass the loop to MAKE_VALGRIND_HAPPY() so it's explicit on which loop
needs to be cleaned up. Since it asserts on uv_loop_close(), need to
remove a couple of those that were being done before the call.

Cleanup where loop was assigned, so the entire test either uses loop or
uv_default_loop(). Not both.

Also take care of any reqs that may have been left uncleaned.
2023-03-12 14:59:00 +01:00
Ben Noordhuis
9581e3df0c
test: fix visual studio 2015 build error (#3918) 2023-03-10 11:41:35 +01:00
Jameson Nash
964f79f7c8
barrier: wait for prior out before next in (#3905)
This code would previously get confused between rounds of the barrier
being called and a thread might incorrectly get stuck (deadlock) if the
next round started before that thread had exited the current round.

Avoid that by not starting the next round in++ before out-- has reached
zero indicating that all threads have left the prior round.

And fix it that on Windows by replacing the implementation with the one
from unix. There are some awkward platform-specific redirection here
with an extra malloc that is not needed on Win32, but that will be fixed
in libuv v2.

Fixes: https://github.com/libuv/libuv/issue/3872
2023-03-06 17:57:25 -05:00
Trevor Norris
460accf9be
test: make valgrind happy (#3916)
Missing a call to MAKE_VALGRIND_HAPPY() to silence valgrind output.
2023-03-03 15:52:31 -05:00
Ben Noordhuis
84525b26fe
test: remove timing-sensitive check (#3899)
Remove expectations around uv_cond_timedwait() maximum sleep time.

The OpenBSD buildbot sleeps more than 5x longer than requested. It no
longer makes sense to expect some reasonable upper bound because at that
point we've moved well beyond reasonable.

Fixes: https://github.com/libuv/libuv/issues/3896
2023-02-07 11:15:59 -05:00
Ben Noordhuis
f1b4c76648
test: remove bad tty window size assumption (#3895)
Fixes: https://github.com/libuv/libuv/issues/3894
2023-01-31 18:35:18 +01:00
Jameson Nash
ee206367d4
build,test: fix distcheck errors (#3886)
When run under distcheck, the libuv source permissions are read-only,
which makes this test copyfile fail without explicit correction to the
permissions.
2023-01-22 15:26:22 -06:00
James McCoy
2638237e1f
build: add CI for OpenBSD and FreeBSD (#3548)
Fixes: https://github.com/libuv/libuv/issues/3510
2023-01-21 13:52:36 +01:00
Ben Noordhuis
a3b7dfcfca test: cond-skip tcp_writealot
Too slow to run under ThreadSanitizer.

Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
bcbaf671a9 test: cond-skip signal_multiple_loops
ThreadSanitizer's complaints about data races are likely legitimate but
they are pre-existing and not straightforward to fix with the current
design. Something for later.

Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
c58cd28279 test: cond-skip fork_threadpool_queue_work_simple
Skip the test when ThreadSanitizer is active because the latter doesn't
support forking in multi-threaded processes.

Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
f328457cb1 test: fix ThreadSanitizer data race warning
Legitimate if fairly benign warning: the `stop` global variable was
read and written without proper synchronization; `volatile` isn't
sufficient.

Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
7b5a21deaa test: fix ThreadSanitizer data race warning
Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
895a1c03be test: fix ThreadSanitizer data race warning
Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
679d679f25 test: fix ThreadSanitizer thread leak warning
Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
panran
a4ba1bd73e
test: fix some warnings when compiling tests (#3816)
```
warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
note: in expansion of macro 'ASSERT_BASE'
#define ASSERT_EQ(a, b) ASSERT_BASE(a, ==, b, int64_t, PRId64)

warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but
argument 3 has type ‘uint32_t’ {aka ‘unsigned int’}
```

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2023-01-19 10:48:13 -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
Darshan Sen
7fd7e8264f
win,fs: fix readlink errno for a non-symlink file (#3719)
In Node.js, fs.readlink() on a non-symlink file used to throw an UNKNOWN
error on Windows. This change maps ERROR_NOT_A_REPARSE_POINT to
UV_EINVAL, so that now it throws EINVAL just like other platforms.

This is handled explicitly in `fs__readlink`, since elsewhere it might
map to EPERM instead (such as in `link`).
2023-01-17 21:04:52 -06:00
Ben Noordhuis
5ee455ffc2
build: enable platform_output test on qemu (#3878)
The test was disabled because of a qemu bug that is presumed to have
since been fixed.

Refs: https://github.com/libuv/libuv/pull/3861
2023-01-12 15:22:19 +01:00
Ben Noordhuis
d5cfb89959
test: unflake fs_event_watch_dir test (#3863)
Increase the timer interval. That hopefully ameliorates the problem of
FSEvents.framework missing events on the macOS CI buildbot.

Not really a fix, more a mitigation.

Fixes: https://github.com/libuv/libuv/issues/3862
2022-12-21 07:51:50 +01:00
Santiago Gimeno
abf77a9eda
test: fix some unreachable code warnings (#3851) 2022-12-10 19:36:46 +01:00
Santiago Gimeno
e1143f1265 win: fixes in uv__pipe_try_write() (#3825 2/2)
Return `UV_EAGAIN` on `ERROR_OPERATION_ABORTED`.
Use the correct format for `overlapped.hEvent`.
Some refactoring to always wait for the overlapped result.
Modernize tests and some improvements.
2022-12-01 23:16:58 +01: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
Ben Noordhuis
5102b2c093
unix: drop kfreebsd support (#3835)
Because kFreeBSD is dead. RIP.

Fixes: https://github.com/libuv/libuv/issues/3833
2022-11-28 22:45:28 +01:00
Ben Noordhuis
238ba3b625
test: fix -Wunused-but-set-variable warnings (#3829) 2022-11-26 22:30:04 +01:00
Tim Besard
988d225cf0
unix,win: add uv_get_available_memory() (#3754) 2022-11-24 22:09:32 +01:00
daomingq
64669fdd8d
thread: add uv_thread_getcpu() (#3803)
Add uv_thread_getcpu() api to get the cpu number on which the calling
thread is running.
2022-11-15 18:01:29 +01: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
Santiago Gimeno
96637d032f win,test: change format of TEST_PIPENAME's
So `WaitNamedPipe()` doesn't fail. Increase the number of clients in
`pipe_connect_multiple` so `CreateFile()` returns `ERROR_PIPE_BUSY` and
the codepath leading to `WaitNamedPipe()` is exercised.
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
Saúl Ibarra Corretgé
a7b16bfb33 win: drop code checking for Windows XP / Server 2k3
Our minimum requirements are Windows 8 now.
2022-11-08 06:51:07 +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
Ben Noordhuis
acfe668ecb
build: add MemorySanitizer (MSAN) support (#3788)
- unpoison results from linux system call wrappers

- unpoison results from stat/fstat/lstat to pacify clang 14
  (fixed in later versions)

- add MSAN build option

- turn on MSAN CI build
2022-10-18 23:21:42 +02: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
Ben Noordhuis
48c90d3781 build: upgrade qemu-user-static package
4.2 is three years old by now. The linux/alpha emulator in that version
doesn't support the epoll_create1() system call.
2022-09-19 00:24:24 +02:00
Ben Noordhuis
9d898acc56
test: fix musl libc.a dlerror() test expectation (#3735)
Dynamic loading with musl only works with libc.so because it is
is implemented in musl's dynamic linker, not in libc proper.

libc.a contains just a stub dlopen() that always fails with a "Dynamic
loading not supported" error message. Update the test to handle that.

Fix: https://github.com/libuv/libuv/issues/3706
2022-09-07 11:21:24 -04:00
Ben Noordhuis
495ffca2c2
win: remove stdint-msvc2008.h (#3673)
Support for VS 2008 was removed two years ago in commit a779fccfd so
this file can safely be deleted.
2022-07-15 10:39:14 +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
V-for-Vasili
1b8cc56194
aix,test: uv_backend_fd is not supported by poll (#3621)
Fixes: https://github.com/libuv/libuv/issues/3614
Co-authored-by: Vasili Skurydzin <vasili.skurydzin@ibm.com>
2022-05-13 12:43:28 +02:00
Jameson Nash
ee3718dd71
loop: better align order-of-events behavior between platforms (#3598)
Previously, Windows would always defer event processing to the loop
after they were received. This could cause confusion for users who were
using prepare and idle callbacks, as seen from this bug in nodejs[^1] and
this discussion in libuv[^2], and even some discrepancies in the libuv
tests too[^3].

[^1]: https://github.com/nodejs/node/pull/42340
[^2]: https://github.com/libuv/libuv/discussions/3550
[^3]: See change to test-spawn.c in this PR

So rather than declare those usages to be wrong, we change libuv to meet
those users expectations.

Replaces: https://github.com/libuv/libuv/pull/3585
2022-05-13 12:41:33 +02: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
Ben Noordhuis
a302ad427d
test: rewrite embed test (#3608)
- fix busy loop
- fix multi-thread race conditions
- reduce amount of platform-specific code

Fixes: https://github.com/libuv/libuv/issues/3606
2022-04-27 10:18:40 +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
Hannah Shi
b51e940dfa
test: separate some static variables by test cases (#3567) 2022-04-11 11:22:37 -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
Ben Noordhuis
223e526f27
test: fix flaky file watcher test (#3591)
FSEvents on macOS sometimes sends one change event, sometimes two.
Make the test more lenient.

Fixes #3589.
2022-04-06 13:40:51 +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
V-for-Vasili
9f2ed35da0
test: remove unused declarations in tcp_rst test (#3574)
Refs: https://github.com/libuv/libuv/pull/3482
2022-03-22 15:13:10 -04:00
V-for-Vasili
c1128f3db3
ibmi: Implement UDP disconnect (#3561)
On IBM i a connectionless transport socket can be disconnected by
either setting the addr parameter to NULL or setting the
addr_length parameter to zero, and issuing another connect().

Refs: https://www.ibm.com/docs/en/i/7.4?topic=ssw_ibm_i_74/apis/connec.htm
2022-03-18 12:03:47 +00:00
V-for-Vasili
5ec89b8c50
aix, ibmi: handle server hang when remote sends TCP RST (#3482)
Workaround getsockname() not working for a TCP handle that has
received RST from the remote.

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2022-03-10 23:53:04 +00:00
Ben Noordhuis
f250c6c73e
unix,win: add uv_available_parallelism() (#3499)
Replacement for the usage pattern where people use uv_cpu_info() as an
imperfect heuristic for determining the amount of parallelism that is
available to their programs.

Fixes #3493.
2022-03-04 22:35:14 +01:00
Guilherme Íscaro
56e279021f
test: use closefd in runner-unix.c (#3497)
This commit changes the plain close calls to
the closefd function, which will properly check if
close() returns an error.
2022-02-27 11:49:58 +01:00
Jameson Nash
f3e0bffcb1
core: change uv_get_password uid/gid to unsigned (#3476)
Added in https://github.com/libuv/libuv/pull/742, these values are
typically defined as unsigned (since Linux 2.4). Only -1 is special,
representing an invalid id (e.g. see setreuid).
2022-02-22 10:59:06 -05:00
Ben Noordhuis
e0a5f58d2c
test: fix ipc_send_recv_pipe flakiness (#3478)
The read callback failed to handle the `nread == 0` case, which is rare
to non-existent on the systems we test on but apparently happens often
enough on Solaris on SPARC to draw attention.

Fixes #3469.
2022-02-20 12:17:13 +01:00
Santiago Gimeno
2bc22c40eb test: fix flaky udp_mmsg test
Take into account that the data may not be already available in the
socket causing the `recvmsg()` / `recvmmsg()` calls to return `EAGAIN`
or `EWOULDBLOCK`.

Fixes: https://github.com/libuv/libuv/issues/3479
2022-02-17 17:34:36 +01:00
Momtchil Momtchev
df78de04e4
win,fs: consider broken pipe error a normal EOF (#3053)
This would later get translated in src/win/error.c this way, which
previously could lead to rather confusing and inaccurate error messages.
2022-02-13 01:40:10 -05:00
Ryan Liptak
912bb8c577
test: fix benchmark-ping-udp (#2817)
- Fixes the declaration of the benchmark in benchmark-list.h (it was not
  previously runnable at all)
- Fixes the benchmark itself hanging infinitely because the data was
  being dropped via ICMP Destination Unreachable errors (meaning nread
  was always zero in pinger_read_cb)
    + The data getting lost was fixed by binding the udp socket
- Properly checks for UV_UDP_MMSG_CHUNK, just as an example of what
  should generally be done (buf_free is actually a no-op as the buf is
  allocated on the stack)
2022-02-13 01:04:41 -05:00
Momtchil Momtchev
636cb8633b
bench: add uv_queue_work ping-pong measurement (#3425) 2022-02-13 00:40:35 -05:00
Jameson Nash
939a05633f
loop: add pending work to loop-alive check (#3466)
Pending work may be either (on any platform) pending_queue callbacks or
(on unix) watcher_queue handles to add to the io poll object.
Previously, we might have gotten somewhat stuck if the user caused an
event to be added to one of these in the idle or prepare callbacks, or
was embedding libuv.

Refs: https://github.com/libuv/libuv/pull/3234
Refs: https://github.com/libuv/libuv/issues/3101
Refs: https://github.com/libuv/libuv/pull/3308
2022-02-13 00:12:11 -05:00
Ben Noordhuis
038086dc08
test: remove flaky test ipc_closed_handle (#3464)
The test is very flaky, both on the CI and on people's local machines.

I spent some time trying to fix it but its design is fairly questionable
and it fails to test what it should more often than not because on fast
machines no queueing of data takes place.

Fixes #2307.
2022-02-08 14:18:10 +01:00
Momtchil Momtchev
e89abc80ea
test: fix flaky uv_fs_lutime test (#3424)
Disable `atime` testing for symlink as this test
is dependant on a race condition on some OSes
(Linux is one) as `lstat` updates the `atime`.
As both `mtime` and `atime` are set by the same
syscall, barring an eventual kernel bug, this
test does not omit any error case.
2022-01-31 16:25:05 -05:00
Jeremy Rose
d9e90857f0
process: monitor for exit with kqueue on BSDs (#3441)
This adds a workaround for an xnu kernel bug that sometimes results in
SIGCHLD not being delivered. The workaround is to use kevent to listen
for EVFILT_PROC/NOTE_EXIT events instead of relying on SIGCHLD on *BSD.
 
Apple rdar: FB9529664
Refs: https://github.com/libuv/libuv/pull/3257
2022-01-31 14:49:22 -05:00
Ben Noordhuis
b5fa965bcb
unix: don't allow too small thread stack size (#3423)
uv_thread_create_ex() lets you set a stack size that is smaller than is
safe. It enforces a lower bound of PTHREAD_STACK_MIN (when that constant
is defined) but with musl libc that's still too small to receive signals
on.

Put the lower bound at 8192 or PTHREAD_STACK_MIN, whichever is greater.
The same restriction was already in place for the _default_ stack size.
2022-01-17 09:36:26 +01:00
Ondřej Surý
d5ed7f1256 test: test with maximum recvmmsg buffer (#3419)
The maximum numbers receivable by the recvmmsg call is defined in
src/unix/udp.c as UV__MMSG_MAXWIDTH with the current value being 20.

Align the size of the receive buffer in the mmsg test to receive the
maximum number of UDP packets in the test.
2022-01-15 06:24:37 +01:00
deal
a865f78124
bsd,windows,zos: fix udp disconnect EINVAL (#3350)
Fixes: https://github.com/libuv/libuv/issues/3344
2022-01-03 11:31:29 +01:00
AJ Heller
4075298df2
win,test: fix a few typos
PR-URL: https://github.com/libuv/libuv/pull/3375
2021-11-30 23:22:31 -05:00
Campbell He
c7843ecfbc
unix,win: add uv_ip_name to get name from sockaddr (#3368)
uv_ip_name is a kind of wrapper of uv_ip4_name and uv_ip6_name
which can be used after getaddrinfo to get the IP name directly
from addrinfo.ai_addr.
2021-11-25 10:05:15 +01:00
Jameson Nash
40bf9a89eb
thread: initialize uv_thread_self for all threads (#3357)
In particular, previously the main thread would have an id of NULL,
which was then not valid to use with any other API that expected a
uv_thread_t handle.
2021-11-24 19:34:57 -05:00
Jameson Nash
b2614a10a5
stream: permit read after seeing EOF (#3361)
On some streams (notably TTYs), it is permitted to continue reading
after getting EOF. So still stop reading on EOF, but allow the user to
reset the stream and try to read again (which may just get EOF).

This relaxes the constraint added in ce15b8405e.
Refs: https://github.com/libuv/libuv/pull/3006
2021-11-24 19:25:47 -05:00
Stacey Marshall
e592ebe9d3
sunos: Oracle Developer Studio support (#3374)
Oracle Developer Studio requires public functions to be
defined as "__global" when "-fvisibility=hidden" used as
added by [#3005](https://github.com/libuv/libuv/pull/3005).
For documentation on `__global` see Reducing Symbol Scope in
Oracle Developer Studio C/C++ guide
https://www.oracle.com/solaris/technologies/symbol-scope.html.

fs_utime_round test failed as timespec.tv_nsec conversion to
double resulted in negative number.  Skip this test for
__SPRO_C builds.

Note that it was necessary to have C99 language features
enabled with Studio compiler (-xc99=all) as version v1.41.0
has other commits that have used C99 features.

Tested with:
- cc: Studio 12.6 Sun C 5.15 SunOS_sparc 152881-05 2019/10/30
- gcc (GCC) 11.2.0

Refs: https://github.com/libuv/libuv/pull/3364
2021-11-24 16:10:13 +01:00
Colin Ihrig
69b811f340
Revert "sunos: Oracle Developer Studio support (#3364)"
This reverts commit 96b26b1ee2.

The commit was reported to break libuv on Illumos systems.
2021-11-19 17:12:04 -05:00
Stacey Marshall
96b26b1ee2
sunos: Oracle Developer Studio support (#3364)
Oracle Solaris linker visibility support.  Option "-fvisibility=hidden"
requires public functions to be defined as "__global".

fs_utime_round test failed as timespec.tv_nsec conversion to double
resulted in negative number.  Skipped this test.

Note that it was necessary to compile with C99 language features.
2021-11-18 11:01:47 +01:00
Darshan Sen
9604b61db6
win,fs: fix error code in uv_fs_read() and uv_fs_write() (#3303)
Just like the Unix counterpart, uv_fs_read() and uv_fs_write() should
throw an EBADF instead of throwing an EPERM when the passed fd has not
been opened with the right flags.

Signed-off-by: Darshan Sen <darshan.sen@postman.com>
2021-10-16 15:11:52 +02:00
Darshan Sen
1cefd94d56
build: add windows build to CI (#3212)
Refs: https://github.com/libuv/libuv/issues/3325
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
2021-10-16 12:25:48 +02:00
Jameson Nash
6564ccc900
asan: fix some tests (#3323)
Previously they were just being run incorrectly, but nothing wrong with
the test itself. We were also interpreting an ASAN failure as TEST_SKIP,
so test failures would not actually be reported as CI failures.
2021-10-10 00:57:43 +02:00
Darshan Sen
c852be467e
test: remove dns-server.c as it is not used anywhere (#3313)
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
2021-10-09 14:32:31 +02:00
Ben Noordhuis
a39009a5a9
win,fsevent: fix uv_fs_event_stop() assert
Fix a logic error where calling uv_fs_event_stop() from the event
callback tripped on a `handle->dir_handle != INVALID_HANDLE_VALUE`
assert in uv_fs_event_queue_readdirchanges().

Fixes: https://github.com/libuv/libuv/issues/3258
PR-URL: https://github.com/libuv/libuv/pull/3259
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-09-08 11:30:02 -04:00
Ikko Ashimine
50c337a0b1
test: fix typo in test-tty-escape-sequence-processing.c
postion -> position in several comments

PR-URL: https://github.com/libuv/libuv/pull/3284
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2021-09-08 10:02:11 -04:00
Jameson Nash
bd7fcf1bfc
run test named ip6_sin6_len
This appears to have been missed in the original PR.

Refs: https://github.com/libuv/libuv/pull/2492
Refs: https://github.com/libuv/libuv/issues/2655 (fixes one issue listed)
PR-URL: https://github.com/libuv/libuv/pull/3246
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-07-21 12:39:13 -04:00
Jameson Nash
03f1a6979c
unix,stream: fix loop hang after uv_shutdown
While most users will likely typically call uv_close in their
uv_shutdown callback, some callers (notable nodejs) do not always do
so. This can result in libuv keeping the loop active, even though there
are no outstanding reqs left to handle.

This bug was added in 80f2f826bf, where
the premise of that commit appears to have simply been incorrect, as
demonstrated by the added test.

Refs: https://github.com/libuv/libuv/issues/3202
PR-URL: https://github.com/libuv/libuv/pull/3233
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-07-13 10:54:02 -04:00
Ben Noordhuis
b7466e31e4 idna: fix OOB read in punycode decoder
libuv was vulnerable to out-of-bounds reads in the uv__idna_toascii()
function which is used to convert strings to ASCII. This is called by
the DNS resolution function and can lead to information disclosures or
crashes.

Reported by Eric Sesterhenn in collaboration with Cure53 and ExpressVPN.

Reported-By: Eric Sesterhenn <eric.sesterhenn@x41-dsec.de>
Fixes: https://github.com/libuv/libuv/issues/3147
PR-URL: https://github.com/libuv/libuv-private/pull/1
Refs: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-22918
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2021-07-02 14:07:07 -04:00
Erkhes N
592cd40af8
test: wrong pointer arithmetic multiplier
PR-URL: https://github.com/libuv/libuv/pull/3216
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2021-06-30 23:24:35 -04:00
Darshan Sen
103dbaede3
Revert "win,fs: correct error code in uv_fs_read and uv_fs_write"
This reverts commit 9394216828.

Refs: https://github.com/libuv/libuv/pull/3180
Refs: https://github.com/libuv/libuv/pull/3205
PR-URL: https://github.com/libuv/libuv/pull/3211
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2021-06-21 16:03:22 -04:00
Jameson Nash
99eb736b4c
win,tcp: make uv_close work more like unix
This is an attempt to fix some resource management issues on Windows. 

Win32 sockets have an issue where it sends an RST packet if there is an 
outstanding overlapped calls. We can avoid that by being certain to 
explicitly cancel our read and write requests first. 

This also removes some conditional cleanup code, since we might as well 
clean it up eagerly (like unix). Otherwise, it looks to me like these 
might cause the accept callbacks to be run after the endgame had freed 
the memory for them. 

The comment here seems mixed up between send and recv buffers. The 
default behavior on calling `closesocket` is already to do a graceful 
shutdown (see 
https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-closesocket
with default l_onoff=zero) if it is the last open handle. The expected 
behavior if there are pending reads in flight is to send an RST packet, 
notifying the client that the server connection was destroyed before 
acknowledging the EOF. 

Additionally, we need to cancel writes explicitly: we need to notify 
Win32 that it is okay to cancel these writes (so it doesn't also 
generate an RST packet on the wire).

Refs: https://github.com/libuv/libuv/pull/3035
Refs: https://github.com/nodejs/node/pull/35946
Refs: https://github.com/nodejs/node/issues/35904
Fixes: https://github.com/libuv/libuv/issues/3034
PR-URL: https://github.com/libuv/libuv/pull/3036
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-06-10 13:12:07 -04:00
Darshan Sen
9394216828
win,fs: correct error code in uv_fs_read and uv_fs_write
Just like the unix counterpart, uv_fs_read and uv_fs_write should throw 
an EBADF instead of manually throwing an EPERM when the passed fd has 
not been opened with the right access flags. 

PR-URL: https://github.com/libuv/libuv/pull/3180
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2021-05-28 11:07:51 -04:00
Jameson Nash
ce15b8405e
Re-merge "unix,stream: clear read/write states on close/eof"
This reverts commit 46f36e3df1.

PR-URL: https://github.com/libuv/libuv/pull/3006
Refs: https://github.com/libuv/libuv/pull/2967
Refs: https://github.com/libuv/libuv/pull/2409
Refs: https://github.com/libuv/libuv/issues/2943
Refs: https://github.com/libuv/libuv/pull/2968
Refs: https://github.com/nodejs/node/pull/36111
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-05-21 16:20:07 -04:00
bbara
0714eded19
test: log to stdout to conform TAP spec
The TAP specification [1] explicitely states:
A harness must only read TAP output from standard output and
not from standard error.

[1] https://testanything.org/tap-specification.html

PR-URL: https://github.com/libuv/libuv/pull/3153
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2021-05-12 18:45:47 -04:00
Matvii Hodovaniuk
580d1d98e0
benchmark: remove unreachable code
PR-URL: https://github.com/libuv/libuv/pull/3092
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-04-04 17:47:37 +02:00
Zhao Zhili
e24e5cbc2b
test: fix stack-use-after-scope
In both `test-tcp-open` and `test-udp-open`.

PR-URL: https://github.com/libuv/libuv/pull/3137
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-04-04 17:29:54 +02:00
Juan José Arboleda
73084d5604
test: remove string + int warning on udp-pummel
PR-URL: https://github.com/libuv/libuv/pull/3115
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-04-04 17:16:44 +02:00
Yash Ladha
97709e185f
chore: use for(;;) instead of while
In the codebase we have used empty for loop for infinite conditions, so
to bring consistency replaced other occurrences of while in the codebase
with for loop.

PR-URL: https://github.com/libuv/libuv/pull/3128
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-04-04 17:15:35 +02:00
Ondřej Surý
285a5ea819
test: fix test-udp-send-unreachable
To properly handle sending UDP packet to unreachable address.

PR-URL: https://github.com/libuv/libuv/pull/2872
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-02-17 10:30:13 +01:00
Shuowang (Wayne) Zhang
bf1aea0d5b
zos: introduce zoslib
This commit introduces ZOSLIB for z/OS, which is a C/C++ library that
implements additional POSIX APIs not available in the LE C Runtime
Library, and provides API for EBCDIC <-> ASCII conversion. This library
requires the linker to be set to CXX when building for z/OS. ZOSLIB is
designed to be installed separately, and then linked to libuv with the
`-DZOSLIB_DIR` option.

PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
2021-02-15 17:18:16 +00:00
Shuowang (Wayne) Zhang
14d09afa8b
zos: don't use nanosecond timestamp fields
Nanosecond resolution for the timestamp fields `st_atim`, `st_mtim`, and
`st_ctim` are not supported on z/OS.

PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
2021-02-15 17:18:09 +00:00
tjarlama
270d05189c
test: move to ASSERT_NULL and ASSERT_NOT_NULL test macros
Moving to new style test macros will make debugging easier in case
of test failure and improve redability. This commit will replace all
ASSERT macros matching the statement:
`ASSERT(identifier (== or !=) value);`
to:
`ASSERT_(NOT_)NULL(identifier);`

Refs: https://github.com/libuv/libuv/issues/2974
PR-URL: https://github.com/libuv/libuv/pull/3081
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-02-14 10:05:46 +01:00
cjihrig
9c3d692b39
test: fix 'incompatible pointer types' warnings
Refs: https://github.com/libuv/libuv/pull/2686
PR-URL: https://github.com/libuv/libuv/pull/3088
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-01-16 15:07:57 -05:00
Issam E. Maghni
f2c88e037c
test: fix some warnings
Fix declaration after statement and comment syntax.

PR-URL: https://github.com/libuv/libuv/pull/3067
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2020-12-29 11:51:08 +01:00
Bob Weinand
c9406ba0e3
poll,unix: ensure safety of rapid fd reuse
Consider the following scenario:

uv_poll_init(loop, poll, fd);
uv_poll_start(poll, UV_READABLE, cb);
// the cb gets invoked etc.
uv_poll_stop(poll);

close(fd);
fd = allocate_new_socket(); // allocate_new_socket() is assigned the same fd by "bad luck" from the OS

// some time later:
uv_poll_init(loop, otherpoll, fd);
uv_poll_start(otherpoll, UV_READABLE, cb);

uv_close(poll); // uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.

According to documentation, "however the fd can be safely closed
immediately after a call to uv_poll_stop() or uv_close()."
Though, in this scenario, we close()'d our file descriptor, and by
bad luck we got the same file descriptor again and register a new
handle for it and start polling.

Previously that would lead to an assertion failure, if we were to
properly free the original handle via uv_close().

This commit fixes that by moving the check whether a only a single
poll handle is active to uv_poll_start() instead of the stopping
routines.

Fixes: https://github.com/libuv/libuv/issues/1172
Fixes: https://github.com/bwoebi/php-uv/issues/81
Fixes: https://github.com/b2wdigital/aiologger/issues/82
Fixes: https://github.com/invenia/LibPQ.jl/issues/140
PR-URL: https://github.com/libuv/libuv/pull/2686
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-12-28 11:51:23 -05:00
Ben Noordhuis
a779fccfd1
win: bump minimum supported version to windows 8
* Windows 7 went out of support earlier this year.

* As did Python 2.7. We no longer have to worry about MSVC 2008.
  Python 3.5 and up use VS 2015.

PR-URL: https://github.com/libuv/libuv/pull/2821
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Joao Reis <reis@janeasystems.com>
2020-12-28 12:44:29 +01:00
Nikolai Vavilov
dd8662b6d2
win, fs: mkdir really return UV_EINVAL for invalid names
Makes uv_fs_mkdir return UV_EINVAL for invalid directory names instead
of UV_ENOENT.

Refs: https://github.com/nodejs/node/issues/31177
PR-URL: https://github.com/libuv/libuv/pull/2601
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2020-12-28 12:01:51 +01:00
Drew DeVault
7b84b1541c
test-getaddrinfo: use example.invalid
RFC 2606 reserves the .invalid top-level domain for this purpose.

PR-URL: https://github.com/libuv/libuv/pull/3063
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2020-12-28 09:33:01 +01:00
Santiago Gimeno
263516e0a0
unix,fs: fix uv_fs_sendfile()
Fix the `off_in` argument  in `copy_file_range()`.

Fixes: https://github.com/libuv/libuv/issues/3056
PR-URL: https://github.com/libuv/libuv/pull/3058
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-12-03 17:07:16 +01:00
Jameson Nash
dde98158b5 test: ensure reliable floating point comparison
Without `volatile`, the x87 hardware may re-organize the comparison math
and end up with the wrong answer.

Fixes: one bullet point item of
    https://github.com/libuv/libuv/issues/2655 and the tests from
    https://github.com/libuv/libuv/pull/849 in certain build configurations
PR-URL: https://github.com/libuv/libuv/pull/2747
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-11-28 10:48:40 -05:00
Ben Noordhuis
8d5af5e70e fs: fix utime/futime timestamp rounding errors
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as
a `double` and then convert it to `struct timeval` or `struct timespec`
where necessary but the calculation for the sub-second part exhibited
rounding errors for dates in the deep past or the far-flung future,
causing the timestamps to be off by sometimes over half a second on
unix, or to be reinterpreted as unsigned and end up off by more than
just sign but many also decades.

Fixes: https://github.com/nodejs/node/issues/32369 (partially)
PR-URL: https://github.com/libuv/libuv/pull/2747
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-11-28 10:48:18 -05:00
Ben Noordhuis
e823d729ab test: remove unnecessary uv_fs_stat() calls
`check_utime()` already calls `uv_fs_stat()`, no point in doing it
twice.

PR-URL: https://github.com/libuv/libuv/pull/2747
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-11-28 10:48:14 -05:00
Jameson Nash
4ddc292774
stream: add uv_pipe and uv_socketpair to the API
Equivalents of `pipe` and `socketpair` for cross-platform use.

PR-URL: https://github.com/libuv/libuv/pull/2953
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2020-11-09 21:50:09 -05:00
Ben Noordhuis
48cf8c8286 unix,win: more uv_read_start() argument validation
Return `UV_EINVAL` when one or more arguments are NULL.

Fixes: https://github.com/libuv/help/issues/137
PR-URL: https://github.com/libuv/libuv/pull/2795
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2020-11-05 16:41:44 -05:00
Ben Noordhuis
06b7317422 unix,win: harmonize uv_read_start() error handling
The behavior of `uv_read_start()` when the handle is closing or already
busy reading wasn't consistent across platforms. Now it is.

Fixes: https://github.com/libuv/help/issues/137
PR-URL: https://github.com/libuv/libuv/pull/2795
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2020-11-05 16:41:44 -05:00
Santiago Gimeno
694f23429b
test: fix pump and tcp_write_batch benchmarks
PR-URL: https://github.com/libuv/libuv/pull/2982
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-10-31 16:42:49 +01:00
Ben Noordhuis
726af5ebc3 unix: report bind error in uv_tcp_connect()
Fix a bug where libuv forgets about EADDRINUSE errors reported earlier:
uv_tcp_bind() + uv_tcp_connect() seemingly succeed but the socket isn't
actually bound to the requested address.

This bug goes back to at least 2011 if indeed it ever worked at all.

PR-URL: https://github.com/libuv/libuv/pull/2218
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-10-27 13:00:59 -04:00
gengjiawen
97a903309f build: add asan checks
Fixes: https://github.com/libuv/libuv/issues/2999
PR-URL: https://github.com/libuv/libuv/pull/2998
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-10-21 14:52:58 +02:00
Elad Lahav
ed5b42d5b7
build,unix: add QNX support
Refs: https://github.com/libuv/libuv/pull/2881
PR-URL: https://github.com/libuv/libuv/pull/2991
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-09-22 23:14:46 -04:00
Ulrik Strid
2a1b880f54
unix,win: add uv_timer_get_due_in()
Co-authored-by: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Refs: https://github.com/nodejs/node-report/pull/73
Refs: https://github.com/libuv/libuv/pull/1255
Fixes: https://github.com/libuv/libuv/issues/2950
PR-URL: https://github.com/libuv/libuv/pull/2951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-09-21 22:15:46 -04:00
Vladimír Čunát
c4e50d9ff5
test: fix compiler warning
PR-URL: https://github.com/libuv/libuv/pull/2992
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-09-20 11:36:47 -04:00
Santiago Gimeno
13ca3bfae8
win,udp: fix error code returned by connect()
PR-URL: https://github.com/libuv/libuv/pull/2981
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-09-20 11:07:42 -04:00
Ryan Liptak
ea17e1cffb
udp: add UV_UDP_MMSG_FREE recv_cb flag
Refs: https://github.com/libuv/libuv/issues/2822
PR-URL: https://github.com/libuv/libuv/pull/2836
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-09-02 20:21:07 -04:00
cjihrig
46f36e3df1
Revert "unix,stream: clear read/write states on close/eof"
This reverts commit 12be29f185.

The commit in question was introducing failures in the Node.js
test suite.

Refs: https://github.com/libuv/libuv/issues/2943
Refs: https://github.com/libuv/libuv/pull/2967
Refs: https://github.com/libuv/libuv/pull/2409
PR-URL: https://github.com/libuv/libuv/pull/2968
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-08-24 13:38:46 -04:00
Jameson Nash
79c531cb7d
nfci: address some style nits
PR-URL: https://github.com/libuv/libuv/pull/2954
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-08-21 17:25:42 -04:00
Bartosz Sosnowski
99e88edf73 tcp: fail instantly if local port is unbound
On Windows when connecting to an unavailable port, the connect() will
retry for 2s, even on loopback devices. This uses a call to WSAIoctl to
make the connect() call fail instantly on local connections.

PR-URL: https://github.com/libuv/libuv/pull/2896
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-13 17:07:21 +02:00
tjarlama
904b1c9b47
test: avoid double evaluation in ASSERT_BASE macro
Passing expression as an argument to a function-like macro will replace
all occurrence of the arguments with expressions during preprocessing.
This result in multiple evaluation of the same expression and can
slow-down the program or even change program state. Here ASSERT_BASE
macro gets an expression involving a and b as first argument and macro
definition has a print statement with a and b, which means there is
double evaluation of a and b when the expression evaluates to false. To
avoid double evaluation temporary variables are created to store results
of a and b.

Since the expression argument is dropped from ASSERT_BASE, the macro no
longer works for string assertions. So a new macro, ASSERT_BASE_STR, is
introduced to deal with strings. ASSERT_BASE can still work with
pointers.

Fixes: https://github.com/libuv/libuv/issues/2916
PR-URL: https://github.com/libuv/libuv/pull/2926
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-12 13:13:02 -04:00
tjarlama
e208100fc9
fs: clobber req->path on uv_fs_mkstemp() error
Contents of template variable passed for posix call mkstemp on error
code EINVAL is unknown. On AIX platform, template will get clobbered
on EINVAL and any attempt to read template might result in error.

In libuv, req->path is passed directly to the mkstemp call and
behavior of this string on error is platform dependent. To avoid
portability issues, it's better to have a common behavior on all
platform. For both unix and windows platform libuv will rewrite path
with an empty string on all error cases.

Fixes: https://github.com/libuv/libuv/issues/2913
Refs: https://github.com/nodejs/node/pull/33549
Refs: https://github.com/libuv/libuv/pull/2933
PR-URL: https://github.com/libuv/libuv/pull/2938
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-12 00:27:26 -04:00
Richard Lau
ea92e9c720
aix: protect uv_exepath() from uv_set_process_title()
Store a copy of the original argv[0] to protect `uv_exepath()`
against `uv_set_process_title()` changing the value of argv[0].

Extract common code for finding a program on the current PATH.

Fixes: https://github.com/libuv/libuv/issues/2674
PR-URL: https://github.com/libuv/libuv/pull/2677
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-10 11:27:30 -04:00
cjihrig
278cfa0183
unix: handle src, dest same in uv_fs_copyfile()
This commit handles the case where the source and destination
are the same. This behavior was originally addressed in #2298,
but the test added in that PR doesn't validate the file size
after the operation. This commit also updates the test to check
for that case.

Refs: https://github.com/libuv/libuv/pull/2298
Refs: https://github.com/nodejs/node/issues/34624
PR-URL: https://github.com/libuv/libuv/pull/2947
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-09 11:13:39 -04:00
Jiawen Geng
b2cec846ef
build: add more failed test, for qemu version bump
Fixes: https://github.com/libuv/libuv/pull/2937
PR-URL: https://github.com/libuv/libuv/pull/2939
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-07 10:58:12 -04:00
Jameson Nash
45f2395f5c
test: give hrtime test a custom 20s timeout
The test is supposed to complete in about 3.5s but it can
hit the 10s timeout when run on a system with high load.

Fixes: https://github.com/libuv/libuv/issues/2342 (hopefully?)
Refs: https://github.com/libuv/libuv/pull/2345
PR-URL: https://github.com/libuv/libuv/pull/2944
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2020-08-06 11:42:08 -04:00
Ben Noordhuis
e44781a161 test: fix thread race in process_title_threadsafe
Libuv calls uv__process_title_cleanup() on shutdown, which raced with
one of the threads from the test that calls uv_get_process_title() in
an infinite loop. Change the test to properly shut down the thread
before exiting.

PR-URL: https://github.com/libuv/libuv/pull/2946
Refs: https://github.com/libuv/libuv/pull/2853#issuecomment-665259082
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-06 10:18:29 +02:00
Trevor Norris
e8effd4556 core: add API to measure event loop idle time
The API addition `uv_metrics_idle_time()` is a thread safe call that
allows the user to retrieve the amount of time the event loop has spent
in the kernel's event provider (i.e. poll). It was done this way to
allow retrieving this value without needing to interrupt the execution
of the event loop. This option can be enabled by passing
`UV_METRICS_IDLE_TIME` to `uv_loop_configure()`.

One important aspect of this change is, when enabled, to always first
call the event provider with a `timeout == 0`. This allows libuv to know
whether any events were waiting in the event queue when the event
provider was called. The importance of this is because libuv is tracking
the amount of "idle time", not "poll time". Thus the provider entry time
is not recorded when `timeout == 0` (the event provider never idles in
this case).

While this does add a small amount of overhead, when enabled, but the
overhead decreases when the event loop has a heavier load. This is
because poll events will be waiting when the event provider is called.
Thus never actually recording the provider entry time.

Checking if `uv_loop_t` is configured with `UV_METRICS_IDLE_TIME` always
happens in `uv__metrics_set_provider_entry_time()` and
`uv__metrics_update_idle_time()`. Making the conditional logic wrapping
each call simpler and allows for instrumentation to always hook into
those two function calls.

Rather than placing the fields directly on `uv__loop_internal_fields_t`
add the struct `uv__loop_metrics_t` as a location for future metrics API
additions.

Tests and additional documentation has been included.

PR-URL: https://github.com/libuv/libuv/pull/2725
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-04 10:31:42 -04:00
Ryan Liptak
6b5aa669db
udp: add uv_udp_using_recvmmsg query
Allows for determining if a buffer large enough for multiple dgrams
should be allocated in alloc_cb of uv_udp_recvstart, for example.
Contributes towards #2822.

PR-URL: https://github.com/libuv/libuv/pull/2830
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-07-28 23:28:18 -04:00
Ryan Liptak
540d723fa4
test: add udp-mmsg test
PR-URL: https://github.com/libuv/libuv/pull/2818
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-07-28 20:14:42 -04:00
Michael Penick
f779fd4f05
win,tcp: avoid reinserting a pending request (#2688)
This fix avoids inserting a duplicate pending request in the case where
`WSARecv()` returns an error (e.g. when a connection has been terminated
by its peer) when `uv_read_start()` is called in a read callback.

Fixes: https://github.com/libuv/libuv/issues/2687
PR-URL: https://github.com/libuv/libuv/pull/2688
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-07-28 13:59:08 -04:00
OleksandrKvl
12be29f185 unix,stream: clear read/write states on close/eof
Fixes: https://github.com/libuv/libuv/issues/1798
Refs: https://github.com/libuv/libuv/pull/1825
PR-URL: https://github.com/libuv/libuv/pull/2409
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Co-Authored-By: Jameson Nash <vtjnash@gmail.com>
2020-07-28 09:05:05 -04:00
Santiago Gimeno
84305d8560
udp: fix write_queue cleanup on sendmmsg error
This issue manifested on `connected` udp sockets trying to send
datagrams to a non-existent server and returning `ECONNREFUSED` because
an ICMP error was received before the actual sending was performed.

PR-URL: https://github.com/libuv/libuv/pull/2899
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-07-02 21:29:42 +02:00
cjihrig
c70ce9b95f
test: extend fs_event_error_reporting timeout
This test was consistently timing out on macOS. Some printf()
debugging on the CI showed that the test was still making forward
progress, but legitimately timed out. This commit bumps the test
timeout to a value that should provide much more than enough time.

Fixes: https://github.com/libuv/libuv/issues/2775
PR-URL: https://github.com/libuv/libuv/pull/2865
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2020-06-02 16:47:58 -04:00
gengjiawen
91a38b18c6
test: skip signal_multiple_loops test on QEMU
Fixes: https://github.com/libuv/libuv/issues/2859
PR-URL: https://github.com/libuv/libuv/pull/2860
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-06-02 10:35:17 -04:00
gengjiawen
1c976110d5
build: test on more platforms via QEMU in CI
This commit runs the test suite via QEMU on GitHub Actions on
a variety of platforms.

Fixes: https://github.com/libuv/libuv/issues/2842
PR-URL: https://github.com/libuv/libuv/pull/2846
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2020-05-17 10:03:20 -04:00