3901 Commits

Author SHA1 Message Date
Azat Khuzhin
cd57e38c3f http: remove message in case !Content-Length and Connection!=close
Since [1] GET can have body, and hence for every incomming connection it
will print this error.

[1] db483e3b002b33890fc88cadd77f6fd1fccad2d2 ("Allow bodies for
GET/DELETE/OPTIONS/CONNECT")

Noticed-by: BotoX (irc)
Refs: #408
2018-02-20 12:12:19 +03:00
Azat Khuzhin
93913da1c4 buffer: fix incorrect unlock of the buffer mutex (for deferred callbacks)
TSAN reports:
  WARNING: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread) (pid=17111)
      #0 pthread_mutex_unlock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3621 (libtsan.so.0+0x00000003b71c)
      #1 evbuffer_add <null> (libevent_core-2.2.so.1+0x00000000ddb6)
      ...

    Mutex M392 (0x7b0c00000f00) created at:
      #0 pthread_mutex_init /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors.cc:1117 (libtsan.so.0+0x0000000291af)
      #1 <null> <null> (libevent_pthreads-2.2.so.1+0x000000000d46)
      ...

$ addr2line -e /lib/libevent_core-2.2.so.1 0x00000000ddb6
/src/libevent/buffer.c:1815 (discriminator 1)

Introduced-in: ae2b84b2575be93d0aebba5c0b78453836f89f3c ("Replace
deferred_cbs with event_callback-based implementation.")
2018-02-12 19:54:27 +03:00
Dmitry Alimov
f24b28e4af
Fix typos in comments 2018-01-15 17:30:08 +03:00
Azat Khuzhin
61c2149268 http: fix leaks in evhttp_uriencode()
Fixes: #584
2018-01-09 21:47:57 +03:00
Azat Khuzhin
416b48ba7a Merge branch 'listener-immediate-close'
* listener-immediate-close:
  test/listener: cover immediate-close logic
  Immediately stop trying to accept more connections if listener disabled
2018-01-04 19:28:59 +03:00
Azat Khuzhin
cb6995cf78 test/listener: cover immediate-close logic 2018-01-04 19:27:35 +03:00
John Fremlin
e03cd0b7eb Immediately stop trying to accept more connections if listener disabled
This is a refined version of the logic previously in #578

The rationale is that the consumer of sockets may wish to temporarily
delay accepting for some reason (e.g. being out of file-descriptors).
The kernel will then queue them up. The kernel queue is bounded and
programs like NodeJS will actually try to quickly accept and then close
(as the current behaviour before this PR).

However, it seems that libevent should allow the user to choose whether
to accept and respond correctly if the listener is disabled.
2018-01-04 19:26:36 +03:00
Marcin Szewczyk
88a1abe809 Fixed last_with_datap description
Grammar and typo fix
2017-12-18 14:01:52 +01:00
John Fremlin
727bcea130 http: add callback to allow server to decline (and thereby close) incoming connections.
This is important, as otherwise clients can easily exhaust the file
descriptors available on a libevent HTTP server, which can cause
problems in other code which does not handle EMFILE well: for example,
see https://github.com/bitcoin/bitcoin/issues/11368

Closes: #578 (patch cherry picked)
2017-12-18 03:00:04 +03:00
Azat Khuzhin
6e5c15d095 Fix typo in cmake because of which EVENT__SIZEOF_SIZE_T was wrong
Fixes: #580
2017-12-16 23:28:41 +03:00
Greg Hazel
65eb529a9f CONNECT method only takes an authority 2017-12-11 01:03:29 +03:00
yongqing.jiao
6cce7458d0 If precise_time is false, we should not set EVENT_BASE_FLAG_PRECISE_TIMER
Fixes: 630f077c296de61c7b99ed83bf30de11e75e2740 ("Simple unit tests for
monotonic timers")
2017-12-11 00:10:23 +03:00
Azat Khuzhin
bc65ffc14c Merge branch 'evconnlistener-do-not-close-client-fd'
Fixes: #577

* evconnlistener-do-not-close-client-fd:
  listener: cover closing of fd in case evconnlistener_free() called from acceptcb
  Revert "Fix potential fd leak in listener_read_cb()"
2017-12-10 23:57:19 +03:00
Azat Khuzhin
8a460e385a listener: cover closing of fd in case evconnlistener_free() called from acceptcb 2017-12-10 23:56:58 +03:00
Azat Khuzhin
94eae336a2 Revert "Fix potential fd leak in listener_read_cb()"
This reverts commit a695a720cda892c270736d127333d73553842094.

@kgraefe:
  "I believe that this commit is just wrong: if lev->cnt is not 1 after
  the callback, new_fd will still never be closed in listener_read_cb().
  So in that case it is the responsibility of the user's code to close
  the file descriptor (which is fine). But why shouldn't it be in the
  other case? And how does the user's code know?"

And I agree
2017-12-10 23:55:51 +03:00
Andrey Okoshkin
6ee73ea9b0 Fix generation of LibeventConfig.cmake for the installation tree
'LIBEVENT_INCLUDE_DIRS' is properly initialized in 'LibeventConfig.cmake' as
'LibeventConfig.cmake.in' contains usage of 'LIBEVENT_CMAKE_DIR' and
'EVENT_INSTALL_INCLUDE_DIR' variables but not 'EVENT_CMAKE_DIR' and
'EVENT__INCLUDE_DIRS'.
Related typos are fixed.
2017-11-29 11:13:51 +03:00
Azat Khuzhin
c2c08e0203 Add missing includes into openssl-compat.h
Before it depends from the caller #include appropriate headers (at least
for OPENSSL_VERSION_NUMBER), but let's make it independent.

Fixes: #574
2017-11-22 10:35:01 +03:00
Azat Khuzhin
33e363f3df Free dns/event bases in dns-example to avoid leaks 2017-11-20 02:08:08 +03:00
ejurgensen
b49c70cc2e Fix incorrect ref to evhttp_get_decoded_uri in http.h
Replaces reference in the http.h include header file to evhttp_get_decoded_uri
with evhttp_uridecode. There is no function called evhttp_get_decoded_uri.
2017-11-05 12:18:49 +01:00
Azat Khuzhin
306747e51c Fix crashing http server when callback do not reply in place from *gencb*
This is the second hunk of the first patch
5ff8eb26371c4dc56f384b2de35bea2d87814779 ("Fix crashing http server when
callback do not reply in place")

Fixes: #567
2017-11-04 19:15:32 +03:00
lightningkay
3f19c5eb83 cmake doesn't has POLICY CMP0054 in low version 2017-11-04 18:57:00 +03:00
Azat Khuzhin
db483e3b00 Allow bodies for GET/DELETE/OPTIONS/CONNECT
I checked with nginx, and via it's lua bindings it allows body for all
this methods. Also everybody knows that some of web-servers allows body
for GET even though this is not RFC conformant.

Refs: #408
2017-10-30 11:32:13 +03:00
Andreas Gustafsson
99d0a952da Do not crash when evhttp_send_reply_start() is called after a timeout.
This fixes the crash reported in issue #509.  The "would be nice"
items discussed in #509 can be addressed separately.
2017-10-30 11:32:13 +03:00
Azat Khuzhin
5ff8eb2637 Fix crashing http server when callback do not reply in place
General http callback looks like:
  static void http_cb(struct evhttp_request *req, void *arg)
  {
    evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
  }

And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
  static void http_cb(struct evhttp_request *req, void *arg)
  {
    return;
  }

This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
  [err] ../http.c: illegal connection state 7

Because it thinks that read for now is not possible, since there were no
write.

Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.

Reported-by: Cory Fields <cory@coryfields.com>
2017-10-29 20:30:42 +03:00
Azat Khuzhin
da3f2ba22a fix handling of close_notify (ssl) in http with openssl bufferevents
Since it can arrive after we disabled events in that bufferevent and
reseted fd, hence evhttp_error_cb() could be called after
SSL_RECEIVED_SHUTDOWN.

Closes: #557
2017-10-22 02:01:09 +03:00
Kiyoshi Aman
8b0aa7b36a Port event_rpcgen.py and test/check-dumpevents.py to Python 3.
These scripts remain compatible with Python 2.
2017-09-25 11:35:23 +03:00
Azat Khuzhin
62866f98a5 Remove OpenSSL paragram from README
Because it is mauvais ton to use binaries instead of normal packages
(like apt-get in debian, pacman in arch, and others).

Plus that link was borken and according to [1] OpenSSL do not ship
binaries officially.

And personally I don't think that this is not obvious that you need
openssl libraries to build libevent with it's support, and BTW you need
headers too (of course).

[1]: https://www.openssl.org/community/binaries.html
Fixes: #562
2017-09-24 15:14:32 +03:00
Vincent JARDIN
56010f37ae test: fix warning
In function ‘send_a_byte_cb’:
test/regress.c:1853:2: warning: ignoring return value of ‘write’, declared with
attribute warn_unused_result [-Wunused-result]
  (void) write(*sockp, "A", 1);
2017-09-11 21:56:30 +02:00
Carlo Marcelo Arenas Belón
1dfec8a970 configure: avoid false positive in DragonFlyBSD
by default, the max buffer size is 16K and histeresis is at 50%, so
a bigger read is needed to unlock writes than you would expect from
other BSD (512 bytes)

this doesn't introduce any regression on FreeBSD 11.1, OpenBSD 6.1, NetBSD 7.1,
macOS 10.12.6 and of course DragonFlyBSD 4.8.1, and most of them show
a max pipe size of 64K, so the read call should drain them all regardless
of how conservative they are on the free pipe space they will require
(usually 512 bytes) before kevent reports the fd as ready for write.

I couldn't find a reference to which bug this code was trying to look for
and it seems to be there from the beginning of git history so it might be
no longer relevant.

Issue: #548
2017-09-11 01:48:35 +03:00
Carlo Marcelo Arenas Belón
a86f89d333 test: avoid regress hanging in macOS
a backtrace of the process without this patch :
  * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    * frame #0: 0x00007fffb1fb7d96 libsystem_kernel.dylib`kevent + 10
      frame #1: 0x0000000108ed0a58 libevent-2.2.1.dylib`kq_dispatch + 696
      frame #2: 0x0000000108ec53d8 libevent-2.2.1.dylib`event_base_loop + 696
      frame #3: 0x0000000108e1763b regress`test_fork + 1931
      frame #4: 0x0000000108e5c7ad regress`run_legacy_test_fn + 45
      frame #5: 0x0000000108e690aa regress`testcase_run_one + 858
      frame #6: 0x0000000108e6954f regress`tinytest_main + 495
      frame #7: 0x0000000108e5c94b regress`main + 171
      frame #8: 0x00007fffb1e88235 libdyld.dylib`start + 1
      frame #9: 0x00007fffb1e88235 libdyld.dylib`start + 1

Issue: #546
2017-09-11 01:48:35 +03:00
Carlo Marcelo Arenas Belón
506df426db autotools: confirm openssl is working before using
latest versions of macOS provide pkg-config and libraries for an ancient
version of openssl as part of the system, but no headers
2017-09-11 01:17:59 +03:00
Carlo Marcelo Arenas Belón
63c4bf78d6 test: fix 32bit linux regress 2017-09-01 15:50:36 -07:00
Carlo Marcelo Arenas Belón
0ec5edde50 autotools: pass $(OPENSSL_INCS) for samples (FTBFS macOS)
if OpenSSL is in a non standard location, need to pass that information
to any sample that needs it

Closes: #550
2017-08-22 11:28:41 +03:00
Carlo Marcelo Arenas Belón
5698cff73d always define EV_INT16_MIN
somehow missing from 043ae7481f4a73b0f48055a0260afa454f02d136
2017-08-17 12:16:56 -07:00
Redfoxmoon
94e5cc84d5 Add configure check for midipix
Fixes: #540
2017-08-15 12:10:33 +03:00
James Synge
27934f0b39 Fix race in access to ev_res from event loop with event_active()
Detected using ThreadSanitizer, resolved by capturing the value
of ev_res in a local variable while the event is locked, then
passing that captured variable to the callback.

TSAN report:
  I0728 14:35:09.822118   WARNING: ThreadSanitizer: data race (pid=815501)
  I0728 14:35:09.822186     Write of size 2 at 0x7b2c00001bf2 by thread T80 (mutexes: write M1110835549570434736):
  I0728 14:35:09.822248       #0 event_active_nolock_ libevent/event.c:2893:14 (0a2b90577e830d775300664df77d0b91+0x1fdab28)
  I0728 14:35:09.822316       #1 event_active libevent/event.c:2858:2 (0a2b90577e830d775300664df77d0b91+0x1fdd10e)
  I0728 14:35:09.822379       #2 Envoy::Event::TimerImpl::enableTimer(std::chrono::duration<long, std::ratio<1l, 1000l> > const&) envoy/source/common/event/timer_impl.cc:24:5 (0a2b90577e830d775300664df77d0b91+0x459fa0)
  ...

  I0728 14:35:09.824146     Previous read of size 2 at 0x7b2c00001bf2 by main thread:
  I0728 14:35:09.824232       #0 event_process_active_single_queue libevent/event.c:1646:33 (0a2b90577e830d775300664df77d0b91+0x1fdf83d)
  I0728 14:35:09.824350       #1 event_process_active libevent/event.c (0a2b90577e830d775300664df77d0b91+0x1fd9ad8)
  I0728 14:35:09.824445       #2 event_base_loop libevent/event.c:1961 (0a2b90577e830d775300664df77d0b91+0x1fd9ad8)
  I0728 14:35:09.824550       #3 Envoy::Event::DispatcherImpl::run(Envoy::Event::Dispatcher::RunType) envoy/source/common/event/dispatcher_impl.cc:166:3 (0a2b90577e830d775300664df77d0b91+0x4576d9)
  ...

Fixes: #543 (pull-request)
2017-08-15 00:09:04 +03:00
Azat Khuzhin
a10a6f4ed9 Remove check against passed bufferevent in bufferevent_socket_connect()
It is a bit confusing to check against the result of EVUTIL_UPCAST(),
because it can return not NULL for NULL pointers, but for even though
with bufferevent we are fine (because bufferevent is the first field in
bufferevent_private), there are no checks for "bufev" in bufferevent's
API, so just remove it to make it generic.

Fixes: #542
Signed-off-by: Ivan Maidanski <i.maidanski@samsung.com>
Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
2017-08-14 23:16:12 +03:00
Azat Khuzhin
b26996a05d Fix wrong assert in evbuffer_drain()
"chain" cannot be NULL here because we have at least one chain (we
handle empty buffer separatelly) and hence loop will be executed at
least once.

Link: 841ecbd961 (commitcomment-23631347)
Signed-off-by: Ivan Maidanski <i.maidanski@samsung.com>
Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
2017-08-14 23:11:03 +03:00
Azat Khuzhin
e83443ec67 Merge remote-tracking branch 'official/pr/527' -- documentation fixes
* official/pr/527:
  Fix a few trivial documentation typos
  Clarify event_free() documentation regarding pending/active events
2017-07-16 21:40:18 +03:00
Ondřej Kuzník
cf7f5b0dc4 Fix tests with detached builds
Closes: #524
2017-07-16 21:35:05 +03:00
Nikolay Edigaryev
c3a61a13d7 Fix a few trivial documentation typos 2017-07-07 01:24:26 +05:00
Nikolay Edigaryev
2137886d2f Clarify event_free() documentation regarding pending/active events
Currently it's not clear as to whether "first make it non-pending and
non-active" sentence requires user to take some action (e.g. call event_del(),
which event_free() already does internally) or just describes what this
function does from the developer point of view.
2017-07-07 01:22:43 +05:00
Nikolay Edigaryev
808524252f Document some obvious cases where a function might also return NULL
Closes: #525
2017-07-02 13:16:59 +03:00
Azat Khuzhin
cd285e425a Fix event_debug_logging_mask_ exporting on win32 2017-05-29 22:26:16 +03:00
Azat Khuzhin
1771ec0f4a Vagrant test 2017-05-29 22:13:28 +03:00
Azat Khuzhin
3ac4f176ee Revert "Make event_debug_get_logging_mask_() real symbol (win32)"
This reverts commit 5f17c12de021c070501e97268e595da82bf38879.
2017-05-29 22:07:57 +03:00
Azat Khuzhin
5f17c12de0 Make event_debug_get_logging_mask_() real symbol (win32)
I cannot made it work without this, even though dumpbin shows that that symbol
exists in the event_core.dll, event_extra.dll failed to compile:
==> win:      Creating library C:/vagrant/.cmake-vagrant/lib/Debug/event_extra.lib and object C:/vagrant/.cmake-vagrant/lib/Debug/event_extra.exp
==> win: http.obj : error LNK2001: unresolved external symbol _event_debug_logging_mask_ [C:\vagrant\.cmake-vagrant\event_extra_shared.vcxproj]
==> win: C:\vagrant\.cmake-vagrant\bin\Debug\event_extra.dll : fatal error LNK1120: 1 unresolved externals [C:\vagrant\.cmake-vagrant\event_extra_shared.vcxproj]
==> win: Done Building Project "C:\vagrant\.cmake-vagrant\event_extra_shared.vcxproj" (default targets) -- FAILED.

And dumpbin:
  sh-4.1$ /cygdrive/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio\ 12.0/VC/bin/amd64/dumpbin.exe /EXPORTS ./bin/Debug/event_core.dll
M
    202   C9 00059A3C event_debug_logging_mask_ = _event_debug_logging_mask_
2017-05-29 22:01:35 +03:00
Azat Khuzhin
ce3af533f1 Fix visibility issues under (mostly on win32)
Refs: #511
Fixes: 7182c2f561570cd9ceb704623ebe9ae3608c7b43 ("cmake: build SHARED and
STATIC libraries (like autoconf does)")
2017-05-29 22:01:33 +03:00
Azat Khuzhin
2773a5ed5e cmake: set CMP0054 to NEW to avoid variables over expansion (since cmake 3.8)
==> win: CMake Warning (dev) at CMakeLists.txt:782 (elseif):
==> win:   Policy CMP0054 is not set: Only interpret if() arguments as variables or
==> win:   keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
==> win:   details.  Use the cmake_policy command to set the policy and suppress this
==> win:   warning.
==> win:
==> win:   Quoted variables like "MSVC" will no longer be dereferenced when the policy
==> win:   is set to NEW.  Since the policy is not set the OLD behavior will be used.
==> win: This warning is for project developers.  Use -Wno-dev to suppress it.
2017-05-29 21:59:01 +03:00
Azat Khuzhin
8b29b13679 cmake: fix building bench/bench_cascade under win32 (missing getopt)
Because of typo in cmake, now rewrote to make it less error prone (since even
for non-win32 there are variables overlap).
2017-05-29 21:59:01 +03:00