4282 Commits

Author SHA1 Message Date
Azat Khuzhin
30791eccce
http: try to read existing data in buffer under EVHTTP_CON_READ_ON_WRITE_ERROR
There are two possible ways of getting response from the server:
- processing existing bufferevent buffer
- reading from the socket (even after write() errored with -1, it is
still possible)

But we did not tried the first option, only the second one.

Fixes: http/read_on_write_error (on freebsd/osx)
2019-01-29 01:16:48 +03:00
Azat Khuzhin
b8ca5a6820
test: add logging for http/read_on_write_error and rearrange code 2019-01-29 00:51:46 +03:00
Azat Khuzhin
d3dcb5aca9
http: do not call deferred readcb if readcb is not set
Otherwise evhttp_read_cb can be called with invalid connection state:
    http/read_on_write_error: [forking] [msg] libevent using: kqueue
      FAIL ../test/regress_http.c:4079: assert(req)
      FAIL ../test/regress_http.c:4087: assert(req)[err] evhttp_read_cb: illegal connection state 0
2019-01-28 22:20:47 +03:00
Azat Khuzhin
5613bfb8dc
Merge branch 'travis-ci-osx-fixes'
* travis-ci-osx-fixes:
  travis-ci/osx: switch to xcode 10.1, since 9.4 is not compatible with gcc-8
  travis-ci/osx: install gcc and fix CC
2019-01-28 22:19:20 +03:00
Azat Khuzhin
b35b533666
travis-ci/osx: switch to xcode 10.1, since 9.4 is not compatible with gcc-8
Refs: travis-ci/travis-ci#9640
2019-01-28 21:25:23 +03:00
Azat Khuzhin
9432fa2ec6
travis-ci/osx: install gcc and fix CC
Since there is no gcc in osx_image [1]:
    ls: /usr/local/bin/gcc-?.?: No such file or directory

  [1]: https://travis-ci.org/libevent/libevent/jobs/484794192#L95

And use ls(1) over echo(1) to show an error if there is no such file.
2019-01-28 21:22:25 +03:00
Azat Khuzhin
4ffc711617
test: adjust expecting error for getaddrinfo() under EMFILE
When getaddrinfo() cannot allocate file descriptor glibc/musl-libc on
linux report EAI_SYSTEM error. But this is not true for freebsd libc [1]
(and hence apple libc [2]), they report EAI_NONAME error instead, so
adjust expectation.

  [1]: https://github.com/freebsd/freebsd/blob/master/lib/libc/net/getaddrinfo.c
  [2]: https://opensource.apple.com/source/Libc/

Refs: #749
Refs: https://github.com/libevent/libevent/issues/749#issuecomment-457838159
2019-01-26 19:57:37 +03:00
Azat Khuzhin
91a2f1346e
test/nonpersist_readd: use assert helpers
To debug failure under win32 in appveyor:
  https://ci.appveyor.com/project/nmathewson/libevent/builds/21559140/job/dn16qdo1j6sr497t#L1620
2019-01-12 14:14:51 +03:00
Azat Khuzhin
99b231b0d8
rpc: use *_new_with_arg() to match function prototype
In 755fbf16c ("Add void* arguments to request_new and reply_new
evrpc hooks") this new functions had been introduced, but newer used,
what for? So let's use them.
2019-01-11 21:53:07 +03:00
Luke Dashjr
28d7221b85
http: Preserve socket error from listen across closesocket cleanup
Closes: #738 (cherry-picked)
2019-01-07 15:22:39 +03:00
Azat Khuzhin
246f44041e
cmake: support static runtime (MSVC)
Fixes: #737
2018-12-17 21:49:00 +03:00
Azat Khuzhin
51945fd939
appveyor: cover static libs for MSVC 2018-12-17 21:48:10 +03:00
baixiangcpp
972da7c838
fix a comment error
Closes: #736 (cherry-picked)
2018-12-16 00:51:14 +03:00
Fredrik Strupe
f33c2ce5f8 cmake: Fix some typos in option descriptions 2018-12-15 12:54:31 +01:00
Azat Khuzhin
f3f7aa5aff
http: fix connection retries when there more then one request for connection
We should not attemp to establishe the connection if there is retry
timer active, since otherwise there will be a bug.

Imagine next situation:
  con = evhttp_connection_base_new()
  evhttp_connection_set_retries(con, 2)
  req = evhttp_request_new()
  evhttp_make_request(con, req, ...)
  # failed during connecting, and timer for 2 second scheduler (retry_ev)

Then another request scheduled for this evcon:
  evhttp_make_request(con, req, ...)
  # got request from server,
  # and now it tries to read the response from the server
  # (req.kind == EVHTTP_RESPONSE)
  #
  # but at this point retry_ev scheduled,
  # and it schedules the connect again,
  # and after the connect will succeeed, it will pick request with
  # EVHTTP_RESPONSE for sending and this is completelly wrong and will
  # fail in evhttp_make_header_response() since there is no
  # "http_server" for this evcon

This was a long standing issue, that I came across few years ago
firstly, bad only now I had time to dig into it (but right now it was
pretty simple, by limiting amount of CPU for the process and using rr
for debug to go back and forth).
2018-12-12 21:46:27 +03:00
Azat Khuzhin
9d3a415a99
Do not check O_NONBLOCK for invalid fds
Fixes: 6f988ee1 ("Merge branch 'check-O_NONBLOCK-in-debug'")
2018-12-09 14:48:44 +03:00
Azat Khuzhin
e5ec52d100
test-fdleak: fix memory leaks
Fixes: #726
2018-12-08 17:35:53 +03:00
Azat Khuzhin
3e6bec7c1a
travis-ci: do not run coveralls with clang (SIGSEGV)
This will fix coveralls badge

See: https://travis-ci.org/libevent/libevent/jobs/458590276#L1425
2018-12-05 11:48:03 +03:00
Azat Khuzhin
196e3a7b2b
Add mailmap 2018-12-05 11:48:03 +03:00
Azat Khuzhin
1d2ef90032
test: add TT_RETRIABLE for http/cancel_by_host_no_ns
Could fail from time to time in travis-ci:
  https://travis-ci.org/libevent/libevent/jobs/458554097#L1702

Follow-up-for: fe5b0719 ("Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)")
2018-11-23 00:43:40 +03:00
Azat Khuzhin
1a79fd38aa
appveyor: enable parallel build 2018-11-23 00:41:21 +03:00
Azat Khuzhin
90d80ef416
cmake: do not build both (SHARED and STATIC) for MSVC/win32
MSVC does not support SHARED and STATIC libraries with the same name,
so let's just build SHARED libraries by default instead (yes we can add
prefix but let's stick with this).

The reason for this is that in windows shared libraries requires .lib
file too, but this is not static library it is imported library for
shared (doh...), for more info [1] and [2].

  [1]: https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-creation
  [2]: https://blogs.msdn.microsoft.com/oldnewthing/20091013-00/?p=16403

And when we build both static library can and will override shared
library imported part, let's take a look at event_extra.lib:

- before patch [3]:
  $ less libevent-fail/lib/Debug/event_extra.lib | head
  ==> use library:contained_file to view a file in the archive
  rw-rw-rw- 100666/100666  59568 Nov 21 23:55 2018 event_extra_static.dir/Debug/evrpc.obj
  rw-rw-rw- 100666/100666 252219 Nov 21 23:55 2018 event_extra_static.dir/Debug/evdns.obj
  rw-rw-rw- 100666/100666 203850 Nov 21 23:55 2018 event_extra_static.dir/Debug/http.obj
  rw-rw-rw- 100666/100666  25907 Nov 21 23:55 2018 event_extra_static.dir/Debug/event_tagging.obj

  [3]: https://ci.appveyor.com/project/azat/libevent/builds/20472024/job/t0o93v042jai0dj7

- "after patch" [4] (not after but the same effect):
  $ less libevent-ok/lib/Debug/event_extra.lib | head
  ==> use library:contained_file to view a file in the archive
  --------- 0/0    509 Nov 21 23:38 2018 event_extra.dll
  ...

  [4]: https://ci.appveyor.com/project/azat/libevent/builds/20478998/job/ca9k3c76amc4qr76

Refs: #691
2018-11-23 00:41:18 +03:00
Azat Khuzhin
c9a073eae8
cmake: introduce EVENT__LIBRARY_TYPE option
Long time ago in [1] cmake build was forced to compile both libraries
(SHARED and STATIC), since this is how our autotools build works.

  [1]: 7182c2f561570cd9ceb704623ebe9ae3608c7b43 ("cmake: build SHARED and STATIC libraries (like autoconf does)")

And there is no way to configure this (and indeed you need to do this
for MSVC for example), so let's introduce option for this --
EVENT__LIBRARY_TYPE.

Plus now we have INTERFACE libraries, that we can use internally in
libevent's cmake rules to avoid strict to _shared/_static variant of the
libraries to link with samples/tests (we prefer SHARED over STATIC for
linking).

Also bump minimal cmake required version to 3.1 by the following
reasons:
- 3.1 is required for RPATH configuration under APPLE
- 3.0 is required for add_library(INTERFACE) (did not found it in 2.8.x
documentation)
- remove extra conditions
(anyway 3.1 was release 4 years ago, so I guess that most of the systems
will have it)
2018-11-23 00:02:18 +03:00
Azat Khuzhin
d705e8c0e9
cmake: drop redundant add_dependencies() 2018-11-22 22:58:56 +03:00
Azat Khuzhin
4d2f013b5d
Merge branch 'TT_RETRIABLE'
* TT_RETRIABLE:
  Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)
  regress: introduce TT_RETRIABLE

Fixes: #704
2018-11-21 00:10:43 +03:00
Azat Khuzhin
fe5b07199d
Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)
This patch mark testcases that only fail under travis-ci/appveyor with
TT_RETRIABLE, since otherwise there is too much noise, other issues
(like failures under vagrant boxes) would be investigated separatelly.

linux (from travis-ci only):
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_by_host_ns_timeout
- http/cancel_by_host_ns_timeout_inactive_server
- thread/conditions_simple
- util/monotonic_prc_precise
- util/usleep
- main/del_wait

vagrant/ubuntu box (this is the only exception):
- thread/no_events

win32 (from appveyor only):
- main/active_later
- main/persistent_active_timeout

And we should use TT_RETRIABLE over TT_OFF_BY_DEFAULT/TT_SKIP when it
make sense.

But there is still "test-ratelim__group_lim" left.
2018-11-20 23:02:56 +03:00
Azat Khuzhin
63b065be80
regress: introduce TT_RETRIABLE
We have some tests that has false-positive due to real/CPU time bound,
but they are pretty generic and we do not want to skip them by default.

TT_RETRIABLE is the flag that will indicate tinytest to retry the test
in case of failure, use it to avoid next possible false-positives:
- real time-related
- CPU time-related
Since I guess it is better to see/grepping RETRYING messages over
ignoring completely failed builds.

No configuration switch for number of retries was done on purpose (only
3 retries and no more).

And this is how it looks BTW:
  $ gcc ../test/tinytest_demo.c ../test/tinytest.c
  $ ./a.out --verbose --no-fork
  demo/timeout_retry
  demo/timeout_retry:
    FAIL ../test/tinytest_demo.c:201: assert(i != 1): 1 vs 1
    [timeout_retry FAILED]

    [RETRYING timeout_retry (3)]
  demo/timeout_retry:
           OK ../test/tinytest_demo.c:201: assert(i != 1): 2 vs 1
           OK ../test/tinytest_demo.c:213: assert(t2-t1 >= 4): 5 vs 4
           OK ../test/tinytest_demo.c:215: assert(t2-t1 <= 6): 5 vs 6
  1 tests ok.  (0 skipped)
2018-11-20 22:56:28 +03:00
Azat Khuzhin
57765b23c8
bufferevent: add debug messages when .setfd/.getfd/.enable/.disable failed 2018-11-20 06:24:42 +03:00
Azat Khuzhin
b98d32d0c9
http: improve error path for bufferevent_{setfd,enable,disable}()
We have calls to the next functions but do not check return values,
though they can be invalid and it is better to show this somehow.

Also do bufferevent_setfd() first and only after it
bufferevent_enable()/bufferevent_disable() since:
a) it is more natural
b) it will avoid extra operations
c) it will not fail first bufferevent_enable() (this is the case for
   buffbufferevent_async at least)

In this case we could add more information for issues like #709
2018-11-20 06:22:31 +03:00
Azat Khuzhin
3036f15a17
regress_http: fix compilation with !EVENT__HAVE_OPENSSL
Fixes: 811c63f7 ("regress: test for HTTP/HTTPS with IOCP enabled")
2018-11-20 06:22:27 +03:00
Azat Khuzhin
f8d510f617
regress_bufferevent: add TT_IOCP_LEGACY/TT_IOCP 2018-11-13 23:31:16 +03:00
Azat Khuzhin
903c6acea5
t/bench_http: disable buffering (win32 do not show anything otherwise)
Refs: #255
2018-11-13 23:31:16 +03:00
Azat Khuzhin
56f3bdefca
s/http-server: check for EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 2018-11-13 23:24:26 +03:00
Azat Khuzhin
3d815cf220
Merge branch 'iocp-fixes'
* iocp-fixes:
  regress: test for HTTP/HTTPS with IOCP enabled
  bev_async: trigger/run only deferred callbacks
  bev_async: do not initialize timeouts multiple times
  bev_async: set "ok" on setfd if fd>=0 (like we do during creation)
  bev_async: ignore ERROR_INVALID_PARAMETER on .setfd for iocp

Closes: #709
Refs: nmathewson/Libevent#160
2018-11-13 22:47:43 +03:00
Azat Khuzhin
811c63f7bc
regress: test for HTTP/HTTPS with IOCP enabled
Next tests added:
- iocp/http/simple
- iocp/http/https_simple
2018-11-13 22:46:20 +03:00
Azat Khuzhin
908e710d40
bev_async: trigger/run only deferred callbacks
Otherwise callbacks will be runned even without event_loop, due to
nature of IOCP.

A simple example is:
  evhttp_connection_free(client)
  # freeing the client will trigger evhttp_connection_free() for the
  # client on the server side, and hence there will double free
  evhttp_free(server)

Fixes: iocp/http/simple
2018-11-13 22:46:20 +03:00
Azat Khuzhin
2bf673a467
bev_async: do not initialize timeouts multiple times
You cannot event_assign() event multiple times, this is UB, and most
likely will fail.

Fixes: af9b2a7ae0be11c79a909d212b1833a9379e4ba0 ("Initialize async
bufferevent timeout CBs unconditionally")
2018-11-13 22:29:08 +03:00
Azat Khuzhin
e73875dfe2
bev_async: set "ok" on setfd if fd>=0 (like we do during creation)
Otherwise after .setfd, .enable will not work.
2018-11-13 22:29:08 +03:00
Azat Khuzhin
a54c034911
bev_async: ignore ERROR_INVALID_PARAMETER on .setfd for iocp
listener already calls event_iocp_port_associate_() the second call will
return ERROR_INVALID_PARAMETER.
Plus we already ignore it on creation, so why we should care about it
here?
2018-11-13 22:29:08 +03:00
Azat Khuzhin
5dc88b387f
Fix conceivable UAF of the bufferevent in evhttp_connection_free()
Although this is not a problem, since bufferevent uses finalizers and
will free itself only from the loop (well this is not a problem if you
do not play games with various event_base in different threads) it
generates questions, so rewrite it in more reliable way.

Fixes: #712
2018-11-13 22:26:12 +03:00
Azat Khuzhin
7bcf576b39
Use BEV_UPCASE() everywhere
Done with coccinelle and manual line rewrap:
  $ cat > BEV_UPCAST.cocci
  @@
  expression field_;
  expression var;
  @@

  - EVUTIL_UPCAST(var, struct bufferevent_private, field_)
  + BEV_UPCAST(var)

  $ spatch --sp-file BEV_UPCASE.cocci --in-place bufferevent*.c > /dev/null
2018-11-13 22:25:41 +03:00
Azat Khuzhin
b2d4fb4176
regress: add EVENT_NO_FILE_BUFFERING, to disable buffering for stdout/stderr
Useful for win32
2018-11-13 22:25:13 +03:00
Azat Khuzhin
f2da619840
event: add some debug information into loop for event_base_free_queues_()
Refs: 7c8d0152dda18ecc52d3099fea235b04ddb850d9 ("Free event queues even
for recursive finalizers")
2018-11-13 22:24:55 +03:00
Azat Khuzhin
9a4b8ec1b6
Merge branch 'sample-http-server'
Some improvements for http-server sample:
- getopt
- persistent port via -p option
- IOCP for win32 via -I
- disable buffering
- enable debug logging via -v/EVENT_DEBUG_LOGGING_ALL
- cleanup (by signal and separate error path on errors)

* sample-http-server:
  s/http-server: graceful cleanup
  s/http-server: enable debug logging if EVENT_DEBUG_LOGGING_ALL env isset
  s/http-server: turn off buffering (otherwise do output on win32)
  s/http-server: add an option to use IOCP
  s/http-server: add options (for persistent port)

Refs: #709
2018-11-13 11:11:39 +03:00
Azat Khuzhin
bdd71f18b1
s/http-server: graceful cleanup 2018-11-13 11:10:17 +03:00
Azat Khuzhin
41b6b279cd
s/http-server: enable debug logging if EVENT_DEBUG_LOGGING_ALL env isset 2018-11-13 11:10:15 +03:00
Azat Khuzhin
3c8ded5c96
s/http-server: turn off buffering (otherwise do output on win32) 2018-11-13 11:10:12 +03:00
Azat Khuzhin
5d3f9d4d92
s/http-server: add an option to use IOCP 2018-11-13 11:10:11 +03:00
Azat Khuzhin
ed705ba704
s/http-server: add options (for persistent port) 2018-11-13 11:10:08 +03:00
Azat Khuzhin
8c1838beec
Remove Vagrantfile (will be moved into libevent-extras)
Since:
- it is not a library
- this file should have (if I had enough time) enough fixes in itself
  and should not polute libevent history
- it "requires" (it more cleaner to use it in this way) script --
  tools/vagrant-tests.py (indeed, from libevent-extras)
- will has it's own issues/README/...

https://github.com/libevent/libevent-extras
2018-11-08 00:48:34 +03:00