1459 Commits

Author SHA1 Message Date
Kirill Rd
98b7ca30b2
http: allow passing in pre-existing connection bev (#1722)
This patch adds functionality to pass a pre-existing connection
as a bufferevent to `evhttp_connection_base_bufferevent_reuse_new`.

When the bufferevent has an existing fd, the evcon starts
in state `EVCON_IDLE` so that requests can be made immediately.

Signed-off-by: Kirill Rodriguez <theoden8@tutamail.com>
Signed-off-by: Kirill Rodriguez <theoden8@tutamail.com>
Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
2024-11-02 22:39:57 +01:00
CXD
d6dbd7f818
Windows platform supports reading IPv6 addresses for DNS server. (#1701)
When using libevent on the Windows platform in an IPv6 environment, I found that libevent could not read the DNS server address for IPv6 addresses during DNS initialization, resulting in constant DNS resolution failures. Then, on MSDN, I discovered that the GetNetworkParams interface does not support obtaining IPv6 addresses, and they provided another interface, GetAdaptersAddresses, to obtain both IPv4 and IPv6 addresses. Therefore, I replaced the GetNetworkParams interface with the GetAdaptersAddresses interface. Please review whether this modification can be merged into the master branch.

Reference MSDN documentation:
https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getnetworkparams
https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses

Co-authored-by: alphacheng <alphacheng@tencent.com>
Co-authored-by: Azat Khuzhin <azat@libevent.org>
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
2024-11-02 18:26:59 +01:00
Kirill Rodriguez
6f35d4dfe8
probably platform caching at work too, let's make different nodenames
Signed-off-by: Kirill Rodriguez <theoden8@gmail.com>
2024-10-31 14:52:44 +00:00
Kirill Rodriguez
d2facdae42
hitting cache makes cancel stress test unreliable
Signed-off-by: Kirill Rodriguez <theoden8@gmail.com>
2024-10-31 10:18:22 +00:00
Kirill Rodriguez
e219dd4a6e
return EAI_ADDRFAMILY instead of NULL (propagate to caller)
Signed-off-by: Kirill Rodriguez <theoden8@gmail.com>
2024-11-02 00:53:31 +00:00
Azat Khuzhin
25fa9c7732 test: retry signal tests with SIGALRM no OSX
By some reason even after first ALRM signal received and event loop
returned it is possible to recieve an ALRM one more time (at least one):

    % yes signal/simple_signal.. | head -n 1000 | xargs -I{} -P10 sh -c 'EVENT_DEBUG_LOGGING_ALL= bin/regress --timeout 0 --verbose {} >& /tmp/test.$SECONDS.$RANDOM.log'
    % cat /tmp/test.0.18384.log
    signal/simple_signal: [forking] [debug] event_add: event: 0x16d70f368 (fd 14),     call 0x102704ae8
    [debug] evsig_ensure_saved_: evsignal (14) >= sh_old_max (0), resizing

             OK /Users/ec2-user/libevent/test/regress.c:1086: assert(setitimer(ITIMER_REAL, &itv, NULL) == 0): 0 vs 0[debug] kq_dispatch: kevent reports 1
    [debug] event_active: 0x16d70f368 (fd 14), res 8, callback 0x102704ae8
    [debug] event_process_active: event: 0x16d70f368,    call 0x102704ae8
    [debug] event_del: 0x16d70f368 (fd 14), callback 0x102704ae8
    [debug] event_base_loop: no events registered.

      FAIL /Users/ec2-user/libevent/test/regress.c:1062: ALRM received not from event loop![debug] event_del: 0x16d70f368 (fd 14), callback 0x102704ae8
    [debug] event_base_free_: 0 events freed
    signal/simple_signal: exited with 0 (0)

      [FAILED signal/simple_signal (0 retries)]
    signal/simple_signal_re_order: [forking] [debug] event_add: event: 0x16d70f368 (fd 14),     call 0x102704ae8
    [debug] evsig_ensure_saved_: evsignal (14) >= sh_old_max (0), resizing
    [debug] event_del: 0x16d70f368 (fd 14), callback 0x102704ae8
    [debug] event_add: event: 0x16d70f368 (fd 14),     call 0x102704ae8

             OK /Users/ec2-user/libevent/test/regress.c:1086: assert(setitimer(ITIMER_REAL, &itv, NULL) == 0): 0 vs 0[debug] kq_dispatch: kevent reports 1
    [debug] event_active: 0x16d70f368 (fd 14), res 8, callback 0x102704ae8
    [debug] event_process_active: event: 0x16d70f368,    call 0x102704ae8
    [debug] event_del: 0x16d70f368 (fd 14), callback 0x102704ae8
    [debug] event_base_loop: no events registered.
    [debug] event_del: 0x16d70f368 (fd 14), callback 0x102704ae8
    [debug] event_base_free_: 0 events freed
    signal/simple_signal_re_order: exited with 0 (0)

    1/2 TESTS FAILED. (0 skipped)

Also note, that the problem not only when I run two tests, but only one
as well:

    % bin/regress --timeout 0 --repeat 1000 --verbose --no-fork signal/simple_signal >/tmp/test2.log 2>&1
    signal/simple_signal:
             OK /Users/ec2-user/libevent/test/regress.c:1086: assert(setitimer(ITIMER_REAL, &itv, NULL) == 0): 0 vs 0
    signal/simple_signal:
             OK /Users/ec2-user/libevent/test/regress.c:1086: assert(setitimer(ITIMER_REAL, &itv, NULL) == 0): 0 vs 0
      FAIL /Users/ec2-user/libevent/test/regress.c:1062: ALRM received not from event loop!

I've tried to run under "ktrace trace -Ss -f C4,S0x010c -c" but of
course it does not fails under it (dtruss by some reason did not work
for me).

P.S. Also remove one TT_RETRIABLE for one test, since only setitimer()
causes this.
2024-10-29 09:28:53 +01:00
Azat Khuzhin
29a3eee5ca test: add --repeat option into tinytest 2024-10-29 09:28:53 +01:00
Azat Khuzhin
7b14bc16f2 test: add fallback for SIGALRM 2024-10-29 09:28:53 +01:00
Azat Khuzhin
c94b382577 test: do not ignore setitimer() failures 2024-10-29 09:28:53 +01:00
Azat Khuzhin
ca163ff1e1 test: fix retries of signal tests on apple 2024-10-29 09:28:53 +01:00
Azat Khuzhin
5e427ad98b test: rename signal tests (simple_signal and simple_signal_re_order) 2024-10-29 09:28:53 +01:00
David Goulet
f84896d37f
dns: Return DNS query type on error (#1220)
When calling the user callback after a DNS resolution on error, make
sure to send back the query type (A, AAAA, PTR).

Closes #1219

Signed-off-by: David Goulet <dgoulet@torproject.org>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Co-authored-by: Azat Khuzhin <azat@libevent.org>
2024-10-28 21:50:29 +01:00
Azat Khuzhin
342a0faa50 Avoid loosing previously active events in case of EV_TIMEOUT
Previously all the existing events was lost if the timeout had been
triggered on that event.

Fixes: #1530
2024-10-28 23:46:18 +03:00
Kirill Rd
e30b215f34
Add caching for evdns (#1717)
No evdns will do caching by default (with respect to TTL), to disable this set EVDNS_BASE_NO_CACHE

There are also helpers for manually manage the cache:
- evdns_cache_write()
- evdns_cache_lookup()

Initial PR: #571
Fixes: #1715

Co-authored-by: Greg Hazel <ghazel@gmail.com>
Co-authored-by: Keith Moore <kmoore@clostra.com>
2024-10-24 08:28:53 +02:00
Azat Khuzhin
b219226982 Fix notifying the base in a different thread after removing active timer event
The base should be notified in case of timer removal if that was the
minimal timer in the base.

Reported-by: @moihn (who is also provided the reproducer on which this
test is based on)
Fixes: https://github.com/libevent/libevent/issues/1727
2024-10-21 09:02:56 +02:00
Azat Khuzhin
970a258bc6
CI and tests fixes (#1719) 2024-10-21 10:02:33 +03:00
Kirill Rodriguez
ae635d4b5b
add explicit check for linux 2024-10-20 21:47:17 +01:00
Kirill Rodriguez
c923a184c6
getaddrinfo with localhost does not necessarily read files 2024-10-20 21:43:09 +01:00
Kirill Rodriguez
5755befda6
fix a Werror error 2024-10-20 21:43:05 +01:00
Kirill Rodriguez
370d99244d
mbedtls3 does not support tls<1.3, and tls<1.3 does not support renegotiations. therefore, disable 2024-10-20 21:41:36 +01:00
Azat Khuzhin
77fed76099 tests: add a test for event_free() from callback handler for signals
Refs: https://github.com/libevent/libevent/issues/1287
2024-10-20 21:57:02 +02:00
icy17
d1a90d09dc tests: Fix potential NULL pointer dereference 2024-08-12 10:02:04 +02:00
Dmitry Ilyin
00c94beaf0 ws: allow Upgrade in Connection header anywhere
This will make it work for Firefox, which uses "Connection: keep-alive, Upgrade"
Reimplemented our own evutil_ascii_strcasestr function (same as
non-portable strcasestr)
2024-07-27 09:18:10 +03:00
Cœur
9848df54cc
http: disallow empty header names (#1690)
In theory, we could be more strict, since there is only a subset of allowed characters:
> ```
> tchar          = "!" / "#" / "$" / "%" / "&" / "'" / "*"
>                 / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
>                 / DIGIT / ALPHA
>                 ; any VCHAR, except delimiters
> ```

But I'd skip such verification, unless there is a legitimate interest (versus performances).

Fixes: #1686
2024-07-26 22:53:30 +02:00
Cœur
5485887c47 Check against EVUTIL_INVALID_SOCKET 2024-07-08 10:20:47 +02:00
icy17
3f799ab675 test/test-changelist: add proper exit path 2024-07-08 10:20:47 +02:00
icy17
6f9f2f3a09 test/test-changelist.c: fix potential NULL pointer dereference 2024-07-08 10:19:35 +02:00
Azat Khuzhin
66428fb969 test-closed: fix -Werror=maybe-uninitialized
Follow-up for: https://github.com/libevent/libevent/pull/1680
2024-07-08 10:15:29 +02:00
Cœur
272bd7ddf0
Fix potential Null pointer dereference in test-closed.c (#1680)
* Fix potential Null pointer dereference in test-closed.c

* add err path

* code review: goto err after evutil_socketpair failure

* code review: goto err for event_config_new failure

---------

Co-authored-by: icy17 <1061499390@qq.com>
2024-07-08 10:13:08 +02:00
Cœur
2bc831c889
Fix potential Null pointer dereference in test-time.c (#1681)
* Fix potential Null pointer dereference in test-time.c

* add err path

* code review: free events before base

---------

Co-authored-by: icy17 <1061499390@qq.com>
2024-07-08 10:08:58 +02:00
Cœur
8dd92069d6
Fix potential Null pointer dereference in bench_httpclient.c (#1676)
Co-authored-by: icy17 <1061499390@qq.com>
2024-06-23 21:15:23 +02:00
Cœur
5d830362dd
Fix potential Null pointer dereference in regress_dns.c (#1675)
Co-authored-by: icy17 <1061499390@qq.com>
2024-06-23 21:12:39 +02:00
Cœur
6d8c38afe7 Reducing the number of mingw warnings 2024-06-02 18:21:49 +03:00
Azat Khuzhin
13678f370c
gcc: fix some compiler errors from the new GCC (#1658)
gcc: fix some compiler errors from the new GCC
2024-06-02 00:53:58 +03:00
fanquake
f5b6104319 test: use evutil_timerclear over timerclear 2024-06-01 19:33:53 +03:00
Cœur
b202a72be4 temp size assert for #1632 2024-06-01 19:29:34 +03:00
Andy Pan
e58f1fa615 Fix the -Wint-conversion
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-06-01 18:24:43 +02:00
Andy Pan
ceb6551fa2 gcc: fix the -Wincompatible-pointer-types errors
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-06-01 18:24:43 +02:00
Andy Pan
7a9458c09b
Don't try to set SO_REUSEADDR and SO_REUSEPORT on Unix sockets (#1625) 2024-05-20 11:17:45 +02:00
Azat Khuzhin
0f51ba669a test: mark http/timeout_read_server as retriable 2024-05-06 09:13:00 +02:00
Azat Khuzhin
ba97d94738 test: reset some static vars to avoid affecting other tests 2024-05-06 09:13:00 +02:00
Azat Khuzhin
479b5ed6f4 test: fix printing number of retries for FAILED message 2024-05-06 09:13:00 +02:00
Azat Khuzhin
d538f41f0a test: add debugging for bufferevent/bufferevent_connect_fail_eventcb* 2024-05-06 09:13:00 +02:00
Azat Khuzhin
2d4d1747e9 test: suppress logging for buffer/add_file_leak1
Warnings from this test should be ignored:

    [warn] evbuffer_file_segment_materialize: mmap(5, 0, 0) failed: Invalid argument
2024-05-06 09:13:00 +02:00
Azat Khuzhin
93a76aa275 test: add proper message in case of test failure
Right now it is impossible to understand what had been failed, but
after:

    $ regress thread/conditions_simple
    thread/conditions_simple: [forking]
      FAIL /src/le/libevent/test/regress_thread.c:385: assert(n_signal == 0): 1 vs 0
      [RETRYING thread/conditions_simple (attempts left 2, delay 1 sec)]
    thread/conditions_simple: [forking]
      FAIL /src/le/libevent/test/regress_thread.c:385: assert(n_signal == 0): 1 vs 0
      [RETRYING thread/conditions_simple (attempts left 1, delay 1 sec)]
    thread/conditions_simple: [forking]
      FAIL /src/le/libevent/test/regress_thread.c:385: assert(n_signal == 0): 1 vs 0
      [RETRYING thread/conditions_simple (attempts left 0, delay 1 sec)]
    thread/conditions_simple: [forking]
      FAIL /src/le/libevent/test/regress_thread.c:385: assert(n_signal == 0): 1 vs 0
      [conditions_simple FAILED]

      [FAILED thread/conditions_simple (attempts made -1)]
    1/1 TESTS FAILED. (0 skipped)
2024-05-05 20:22:23 +02:00
Azat Khuzhin
d5745413cc test: fix RETRYING message (add missing group prefix)
Before:

    $ regress thread/conditions_simple
    thread/conditions_simple: [forking]
      FAIL /src/le/libevent/test/regress_thread.c:385: assert(n_signal == 0): 1 vs 0
      [RETRYING conditions_simple (attempts left 2, delay 1 sec)]

After:

    $ regress thread/conditions_simple
    thread/conditions_simple: [forking]
      FAIL /src/le/libevent/test/regress_thread.c:385: assert(n_signal == 0): 1 vs 0
      [RETRYING thread/conditions_simple (attempts left 2, delay 1 sec)]
2024-05-05 20:21:58 +02:00
Cœur
eec47a6710
Fix typos (#1634) 2024-04-30 09:59:58 +02:00
Andy Pan
aef201a9fc
Change ident for EVFILT_USER to 0 and add a test (#1582)
Conventionally, ident for EVFILT_USER is set to 0 to avoid
collision of file descriptors, which is what other renowned
networking frameworks like netty(java), mio(rust), gnet(go),
swift-nio(swift), etc. do currently.

Co-authored-by: Azat Khuzhin <azat@libevent.org>
2024-04-29 07:35:33 +02:00
dockercui
147298a2d1 Fix some comments
Signed-off-by: dockercui <dockercui@aliyun.com>
2024-04-24 08:27:12 +02:00
williammuji
9de85b5834 fix WSOptions enum value and extended payload length bug 2024-04-15 10:31:04 +03:00