3500 Commits

Author SHA1 Message Date
Azat Khuzhin
fad5fe2cc1 be_sock: drop be_sock_add() macro (useless and debug unfriendly) 2015-11-06 10:21:04 +03:00
Azat Khuzhin
3c1f58f58b be: introduce bufferevent_generic_adj_existing_timeouts_()
And use it in openssl/sock layers to avoid copy-pasting it's variants.
2015-11-06 10:21:04 +03:00
Azat Khuzhin
f4b6284b83 be_openssl: don't add events during bev creation (like be_sock)
Using the following examples you can get changes between be_openssl and
be_sock:
$ function diff_addr()
{
    eval diff -u $(printf "<(strip_addr %s) " "$@")
}
$ function strip_addr()
{
    sed 's/0x[a-zA-Z0-9]*/0xFFFF/g' "$@"
}
$ EVENT_DEBUG_LOGGING_ALL= regress --verbose --no-fork +http/https_connection_retry 2> /tmp/https-retry.log >&2
$ EVENT_DEBUG_LOGGING_ALL= regress --verbose --no-fork +http/connection_retry 2> /tmp/http-retry.log >&2
$ diff_addr /tmp/http-retry.log /tmp/https-retry.log
2015-11-06 10:21:04 +03:00
Azat Khuzhin
a96b73b9fd be: add_event: use evutil_timerisset() 2015-11-06 10:21:04 +03:00
Azat Khuzhin
3160716f26 test/regress: fix ssl-less builds (need to make this prettier)
CI: https://travis-ci.org/libevent/libevent/jobs/89590839
2015-11-06 10:21:04 +03:00
Azat Khuzhin
45a284acfd Merge branch 'https-coverage-v6'
This patchset adds some basic tests to cover some https cases:
$ regress +http/https_..
http/https_basic: [forking] OK
http/https_simple: [forking] OK
http/https_simple_dirty: [forking] OK
http/https_incomplete: [forking] OK
http/https_incomplete_timeout: [forking] OK
http/https_connection_retry: [forking] OK
http/https_connection_retry_conn_address: [forking] OK
7 tests ok.  (0 skipped)

But there are some leaks in http regression tests (like init_ssl() and others),
must be fixed by using custom setup routine.

* https-coverage-v6:
  test/http: allow dirty shutdown for ssl to fix https_incomplete
  test/http: https basic
  test/http: incomplete{,_timeout} for https
  test/http: add simplest test for http/https/https_dirty_shutdown
  test/http: https: retry coverage
  test/http: https server support (plus some helpers)
  test/http: more sanity checks
  test/ssl: export getkey()/getcert()/get_ssl_ctx()/init_ssl() for https
2015-11-06 09:47:38 +03:00
Azat Khuzhin
1ede3262cc test/http: allow dirty shutdown for ssl to fix https_incomplete 2015-11-06 09:43:25 +03:00
Azat Khuzhin
59714b46bc test/http: https basic 2015-11-06 09:43:25 +03:00
Azat Khuzhin
615490d048 test/http: incomplete{,_timeout} for https 2015-11-06 09:42:44 +03:00
Azat Khuzhin
93b19dc569 test/http: add simplest test for http/https/https_dirty_shutdown
There is "basic" before, but it uses bufferevent's for creating requests for
http layer, while this test uses http layer for client requests too.
2015-11-06 09:42:43 +03:00
Azat Khuzhin
7c2d24ae6b test/http: https: retry coverage 2015-11-06 09:42:43 +03:00
Azat Khuzhin
a7088ad095 test/http: https server support (plus some helpers)
TODO:
- check BEV_OPT_DEFER_CALLBACKS separately
2015-11-06 09:42:28 +03:00
Azat Khuzhin
a27c53c531 test/http: more sanity checks 2015-11-06 09:29:31 +03:00
Azat Khuzhin
0c4c387c15 test/ssl: export getkey()/getcert()/get_ssl_ctx()/init_ssl() for https 2015-11-05 11:00:06 +03:00
Bill Vaughan
f45d39d1a4 Fix lock leak in be_pair_flush() if flush type is BEV_NORMAL
Fixes: bufferevent/bufferevent_pair_flush_normal
  $ regress --no-fork bufferevent/bufferevent_pair_flush_normal
  bufferevent/bufferevent_pair_flush_normal:
    FAIL ../test/regress_bufferevent.c:181: assert(bufferevent_pair_get_partner(bev1) == NULL): 0x177fa20 vs (nil)
    [bufferevent_pair_flush_normal FAILED]

Fixes #266
2015-10-30 18:55:39 +03:00
Azat Khuzhin
ad52602ffd test/regress_be: basic coverage bufferevent_flush() for pair/sock layers
Refs #266
2015-10-30 18:55:34 +03:00
Azat Khuzhin
f8081afc5e test/regress_be: socket_filter_inactive: check bufferevent after creation
Fixes:
../test/regress_bufferevent.c: In function ‘test_bufferevent_socket_filter_inactive’:
../test/regress_bufferevent.c:1180:1: warning: label ‘end’ defined but not used [-Wunused-label]
 end:
2015-10-30 18:38:09 +03:00
Azat Khuzhin
7c8d0152dd Free event queues even for recursive finalizers
For finalizers we can register yet another finalizer out from finalizer, and
iff finalizer will be in active_later_queue we can add finalizer to
activequeues, and we will have events in activequeues after event_base_free()
returns, which is not what we want (we even have an assertion for this).

A simple case is bufferevent with underlying (i.e. filters) in inactive queue.

Fixes: regress bufferevent/bufferevent_socket_filter_inactive
2015-10-30 14:48:14 +03:00
Azat Khuzhin
337684b8e8 test/regress_be: cover finalizers from inactive to active queue
Right now this will fail with the next assertion:
$ regress --no-fork --verbose bufferevent/bufferevent_socket_filter_inactive
bufferevent/bufferevent_socket_filter_inactive: [err] ../event.c:862: Assertion TAILQ_EMPTY(&base->activequeues[i]) failed in event_base_free_
Aborted
2015-10-30 14:45:20 +03:00
Azat Khuzhin
575ff67885 buffer_compat: fix comment -- we have EVBUFFER_EOL_ANY not EOL_STYLE_ANY 2015-10-30 01:34:40 +03:00
Azat Khuzhin
d8fd4c0742 test/regress_buffer: fix clang compilation warnings
../test/regress_buffer.c:201:12: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses]
          tt_assert(!memcmp((char*)EVBUFFER_DATA(evb), "1/hello", 7) != 0);
2015-10-09 01:55:54 +03:00
Azat Khuzhin
cd422e0927 test/regress_http: fix compilation warnings (-Wmissing-field-initializers) 2015-10-09 01:50:05 +03:00
Azat Khuzhin
f55db9856e test/regress_dns: fix compilation warnings (-Wmissing-field-initializers/for)
I don't have an error for loop because gcc5 have --std=gnu11 by default.
We need some options-consistency for all versions/compilers and build systems
to avoid such patches.

Fixes: https://travis-ci.org/libevent/libevent/jobs/84403473
Fixes: https://travis-ci.org/libevent/libevent/builds/84403463
2015-10-09 01:47:44 +03:00
Azat Khuzhin
d4bdd0c889 Merge branch 'evdns-randomization'
* evdns-randomization:
  evdns: fix randomize-case by make case-insensitive as required
  tests/regress_dns: cover that randomize-case works case-insensitive
  evnds: inline TEST_NAME macro to make debuggin easier

Fixes #288
2015-10-09 01:18:15 +03:00
Azat Khuzhin
9c238deb76 evdns: fix randomize-case by make case-insensitive as required
Interesting that this wasn't found by regression tests since they respond with
that SoME-rAndDom-CaSe domains, and no case-insensitive mode is required during
comparing response from the server and request.

Fixes #288
Covered-by: regress dns/search_lower
2015-10-09 01:13:53 +03:00
Azat Khuzhin
1e8bfbc6bc tests/regress_dns: cover that randomize-case works case-insensitive
Regression-for: #288
2015-10-09 01:12:12 +03:00
Azat Khuzhin
0c615f4ef3 evnds: inline TEST_NAME macro to make debuggin easier 2015-10-09 00:03:47 +03:00
Thomas Bernard
9f02a44513 make test/regress_ssl.c compile without warnings 2015-10-05 12:37:41 +02:00
Azat Khuzhin
e4556fcda7 evthread: fix evthread_setup_global_lock_() for debug-lock with a real-lock case
Sample bt:
  (gdb) bt
  #0  0x00000000004a95d2 in evthread_setup_global_lock_ (lock_=0x0, locktype=0, enable_locks=1)
  #1  0x00000000004afbc7 in evsig_global_setup_locks_ (enable_locks=1) at signal.c:475
  #2  0x00000000004a5da8 in event_global_setup_locks_ (enable_locks=1) at event.c:3838
  #3  0x00000000004a8983 in evthread_set_lock_callbacks (cbs=0x7fffffffdde0) at evthread.c:129
  #4  0x0000000000445a8f in use_lock_unlock_profiler () at regress_bufferevent.c:306
  #5  0x0000000000445af2 in test_bufferevent_pair_release_lock (arg=0x70e710) at regress_bufferevent.c:327
  #6  0x000000000048c9a8 in testcase_run_bare_ (testcase=0x6fdc10 <bufferevent_testcases+80>) at tinytest.c:105
  #7  0x000000000048cc8a in testcase_run_one (group=0x6ff270 <testgroups+112>, testcase=0x6fdc10 <bufferevent_testcases+80>) at tinytest.c:252
  #8  0x000000000048d5c9 in tinytest_main (c=3, v=0x7fffffffe008, groups=0x6ff200 <testgroups>) at tinytest.c:434
  #9  0x000000000047a08f in main (argc=3, argv=0x7fffffffe008) at regress_main.c:459

Found-with: regress bufferevent/bufferevent_pair_release_lock (-DEVENT__DISABLE_DEBUG_MODE=ON)
2015-10-04 03:50:40 +03:00
Azat Khuzhin
f337296a5c Fix checking for make_base_notifiable()
Fixes: a068f2e5 ("event_debug_created_threadable_ctx_: fix compilation without
debug mode")
Found-after: 3e56da23 ("travis: add builds without debug mode into matrix")
2015-10-04 03:37:26 +03:00
Azat Khuzhin
8240379a3c test/regress_be: drop debug __asm__(int3) to fix arm build
Closes #284
2015-10-04 03:19:12 +03:00
Azat Khuzhin
3e56da238c travis: add builds without debug mode into matrix
To cover compilation with this flag, since brew for example uses it by default.
2015-09-30 11:13:44 +03:00
Azat Khuzhin
a068f2e594 event_debug_created_threadable_ctx_: fix compilation without debug mode
The following command failed before:
$ ./configure --disable-debug-mode

Fixes: dcfb19a27b7760299bc9e7291c9abd88c59fd91a ("Debug mode option to error on
evthread init AFTER other event calls.")
2015-09-29 20:42:45 +03:00
Azat Khuzhin
3f749e93db test: fix bufferevent/bufferevent_pair_release_lock in debug mode
After this test had been fixed for freebsd the debug build was broken because
we can't call evthread_set_lock_callbacks() when something already initialized,
and we can't call event_base_free() (in kqueue case) when it is initialized,
because of "held_by", but this only playing role during freeing lock profiler
so reset lock callbacks there before and this will fix both.

Fixes: 79f9ace4ae8a259a5cf1b4ff3869078b60ff16a1 ("test: fix
bufferevent/bufferevent_pair_release_lock for freebsd")

P.S. after this patch 'make verify' finishes without errors on freebsd.
2015-09-10 13:44:07 +03:00
Azat Khuzhin
79f9ace4ae test: fix bufferevent/bufferevent_pair_release_lock for freebsd
On FreeBSD with kqueue there is a call to evthread_debug_lock_mark_unlocked()
during event_base_free(), that will fail with an assert because of unmatched
"held_by", fix this by reseting lock callbacks to NULL before
event_base_free().

Trace:
  bufferevent/bufferevent_pair_release_lock: [warn] Trying to disable lock functions after they have been set up will probaby not work.
  [warn] Trying to disable lock functions after they have been set up will probaby not work.

    FAIL libevent/test/regress_bufferevent.c:259: lock: lock error[err] libevent/evthread.c:277: Assertion lock->held_by == me failed in evthread_debug_lock_mark_unlocked
  [New Thread 802006400 (LWP 100070/regress)]

  Program received signal SIGABRT, Aborted.
  [Switching to Thread 802006400 (LWP 100070/regress)]
  0x000000080167d6ca in thr_kill () from /lib/libc.so.7
  (gdb) bt
  #0  0x000000080167d6ca in thr_kill () from /lib/libc.so.7
  #1  0x0000000801752149 in abort () from /lib/libc.so.7
  #2  0x00000000004dff44 in event_exit (errcode=-559030611) at libevent/log.c:105
  #3  0x00000000004e053c in event_errx (eval=-559030611, fmt=0x5182cc "%s:%d: Assertion %s failed in %s") at libevent/log.c:162
  #4  0x00000000004d9954 in evthread_debug_lock_mark_unlocked (mode=0, lock=0x802017060) at libevent/evthread.c:277
  #5  0x00000000004d909a in debug_lock_unlock (mode=0, lock_=0x802017060) at libevent/evthread.c:290
  #6  0x00000000004e132c in evsig_dealloc_ (base=0x80201e300) at libevent/signal.c:434
  #7  0x00000000004e36c1 in kq_dealloc (base=0x80201e300) at libevent/kqueue.c:435
  #8  0x00000000004c9a44 in event_base_free_ (base=0x80201e300, run_finalizers=1) at libevent/event.c:855
  #9  0x00000000004c931a in event_base_free (base=0x0) at libevent/event.c:887
  #10 0x0000000000452657 in lock_unlock_free_thread_cbs () at libevent/test/regress_bufferevent.c:279
  #11 0x0000000000452621 in free_lock_unlock_profiler (data=0x8020170a0) at libevent/test/regress_bufferevent.c:317
  #12 0x000000000044bc8f in test_bufferevent_pair_release_lock (arg=0x8020170a0) at libevent/test/regress_bufferevent.c:334
  #13 0x00000000004b2288 in testcase_run_bare_ (testcase=0x737660) at libevent/test/tinytest.c:105
  #14 0x00000000004b1e72 in testcase_run_one (group=0x738c90, testcase=0x737660) at libevent/test/tinytest.c:252
  #15 0x00000000004b2930 in tinytest_main (c=3, v=0x7fffffffead0, groups=0x738c20) at libevent/test/tinytest.c:434
  #16 0x00000000004982fe in main (argc=3, argv=0x7fffffffead0) at libevent/test/regress_main.c:459
  (gdb) f 4
  #4  0x00000000004d9954 in evthread_debug_lock_mark_unlocked (mode=0, lock=0x802017060) at libevent/evthread.c:277
  277                     EVUTIL_ASSERT(lock->held_by == me);
  Current language:  auto; currently minimal
  (gdb) p lock
  $1 = (struct debug_lock *) 0x802017060
  (gdb) p lock->held_by
  $2 = 0
  (gdb) p me
  $3 = 34393318400
2015-09-10 12:39:20 +03:00
Azat Khuzhin
484d0db0fb Merge branch 'cloudabi-fixes-pr-278'
Rebased version of #278

* cloudabi-fixes-pr-278:
  Assume that ke_udata is an integer type on CloudABI.
  Add missing include of <netinet/in.h>.
  Include <sys/ioctl.h>, <sys/resource.h> and <sys/wait.h> optionally.
2015-09-10 12:26:48 +03:00
Ed Schouten
5602e451ce Assume that ke_udata is an integer type on CloudABI. 2015-09-10 12:15:42 +03:00
Ed Schouten
b2c68bc22b Add missing include of <netinet/in.h>.
POSIX states that sockaddr_in6 should be declared in <netinet/in.h>. By
including this header, the code now builds on FreeBSD and CloudABI.
2015-09-10 12:14:35 +03:00
Ed Schouten
c1404b5651 Include <sys/ioctl.h>, <sys/resource.h> and <sys/wait.h> optionally.
Though CloudABI implements a very large part of POSIX, it does not
provide these header files, for the reason that there is no raw device
access, no resource limiting and no access to the global process table
through wait().

It looks like these header files are not actually needed in theory.
There don't seem to be any constructs in these source files that use
these features, but I suspect they might still be required on some
systems.
2015-09-10 12:14:27 +03:00
Sebastian Hahn
bfcedee038 Add a prototype for event_disable_debug_mode()
Exporting this function seems rather useless, as debugging mode has to
be enabled early and calling this function doesn't allow it to get
toggled back on later.

Fixes a compile warning when using clang 3.6.

Fixes #271
Fixes #224
2015-09-10 11:53:54 +03:00
Azat Khuzhin
714fc70500 http: export evhttp_connection_set_family()
Fixes #176
2015-09-10 11:46:30 +03:00
Azat Khuzhin
a0f308da99 test/regress_be: bufferevent_enable() shouldn't call eventcb by it's own
It must enter the event loop regardless BEV_OPT_DEFER_CALLBACKS, to avoid
potential errors with subsequent connect(), you will find more info in #43,
since this is a regression for it.
2015-09-10 11:19:08 +03:00
Azat Khuzhin
37dc9e0eca test/regress_be: introduce fake_listener_create() 2015-09-10 11:18:34 +03:00
Azat Khuzhin
9b16d9b845 Merge branch 'evhttp-request-own-fixes'
I hope that I validated all places where evhttp_request_free() called and
ownership of request can be belong to user-specific code.

* evhttp-request-own-fixes:
  http: fix evhttp_request_own() by checking EVHTTP_USER_OWNED in more cases
  test/regress_http: cover evhttp_request_own()

Fixes #68
2015-09-09 19:32:03 +03:00
Azat Khuzhin
b0d3964ff5 http: fix evhttp_request_own() by checking EVHTTP_USER_OWNED in more cases
Suggested-by: @ellzey
Fixes: http/request_own
Fixes: #68
2015-09-09 19:31:12 +03:00
Azat Khuzhin
6f6fa0d28a test/regress_http: cover evhttp_request_own() 2015-09-09 19:15:18 +03:00
Azat Khuzhin
2cba677978 Merge branch 'http-server-EOF-at-read-v3'
This patchset fixes an issue with detecting EOF in http server and add some
regression tests to make sure that we will not break anything.

* http-server-EOF-at-read-v3:
  http: fix detecting EOF without write
  test/regress_http: cover write during read
  test/regress_http: verify that closecb will be called without multiple write

Closes #78
Link: http://stackoverflow.com/questions/18743948/libevent2-http-server-how-to-detect-client-close/18776728?noredirect=1#18776728
2015-09-09 18:08:02 +03:00
Azat Khuzhin
7ed02ac129 http: fix detecting EOF without write
Before this patch http server don't knows when client disconnected until it
will try to write to it, IOW to detect is client still alive you need to write
something to client socket, however it is not convenient since it requires to
store all clients somewhere and poll them periodically, and I don't see any
regressions if we will leave EV_READ always (like libevhtp do), since we
already reset read callback in evhttp_write_buffer() (see
http/write_during_read).

Also since we don't disable EV_READ anymore we don't need some enable EV_READ,
so we will reduce number of epoll_ctl() calls.

Covered-by: http/terminate_chunked_oneshot
Covered-by: http/write_during_read
Fixes: #78
2015-09-09 18:06:42 +03:00
Azat Khuzhin
3d15aeb4fd test/regress_http: cover write during read
This is the regression for evhttp_write_buffer() where we reset readcb to avoid
illegal state:
http/write_during_read: [err] evhttp_read_cb: illegal connection state 7

If you will comment that this test will fail.
2015-09-09 18:06:37 +03:00
Azat Khuzhin
4be6c70bb0 test/regress_http: verify that closecb will be called without multiple write
And now this works incorrect, i.e. http layer will not detect EOF until another
write.

Reported-in: #78
2015-09-08 16:43:05 +03:00