3533 Commits

Author SHA1 Message Date
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
Azat Khuzhin
cf2cf2a01a test: run regress with EVENT_DEBUG_MODE=1 and without
This could show some bugs like "event_assign called on an already added event",
and some others that debugging mode could track.
2015-09-02 19:38:30 +03:00
Azat Khuzhin
6ea66554df test/regress: fix bufferevent_pair_release_lock with EVENT_DEBUG_MODE
Before this patch you will see next error:
$ EVENT_DEBUG_MODE= regress --no-fork bufferevent/bufferevent_pair_release_lock
bufferevent/bufferevent_pair_release_lock: [err] evthread initialization must be called BEFORE anything else!
2015-09-02 19:37:00 +03:00
Azat Khuzhin
4637aa8841 sample/https-client: add -timeout option 2015-09-02 19:34:52 +03:00
Azat Khuzhin
620aae969c Merge branch 'be-openssl-drop-fd_is_set-v4'
This must fix some issues with bufferevent openssl layer + some cleanups.

* be-openssl-drop-fd_is_set-v4:
  be_openssl: don't use *_auto() in do_handshake() we can't have fd == -1 there
  be_openssl: don't call set_open_callbacks() if fd == -1
  be_openssl: introduce be_openssl_auto_fd() helper
  be_openssl: introduce set_open_callbacks_auto()
  be_openssl: get rid off hackish "fd_is_set", to fix some corner cases
2015-09-02 19:34:15 +03:00
Azat Khuzhin
877280db09 be_openssl: don't use *_auto() in do_handshake() we can't have fd == -1 there 2015-09-02 19:28:33 +03:00
Azat Khuzhin
e8a2da96e3 be_openssl: don't call set_open_callbacks() if fd == -1
This must be illegal, firstly we must do set_do handshake and only after this
we could read/write.
2015-09-02 19:27:09 +03:00
Azat Khuzhin
2a8a7112a5 be_openssl: introduce be_openssl_auto_fd() helper 2015-09-02 19:27:01 +03:00
Azat Khuzhin
510da71fae be_openssl: introduce set_open_callbacks_auto()
This will split cases when we need to extract fd (cases when we have fd==-1
passed to set_open_callbacks()), and cases when we mustn't have to do this --
SET_FD via be_openssl_ctrl().
2015-09-02 19:25:21 +03:00
Azat Khuzhin
40b0379833 be_openssl: get rid off hackish "fd_is_set", to fix some corner cases
This patch is a cleanup and a bug fix, it drops ```fd_is_set``` flag, and
replace it with some checks to event_initialized(), and now we will not call
event_assign() on already added event, plus we will delete event when we really
have to (this patch fixes the case when server is down, IOW before this patch
we will not call event_del() because ```fd_is_set``` was reset to 0) and this
will fix some issues with retries in http layer for ssl.

Reported-in: #258
Fixes: regress ssl/bufferevent_socketpair_timeout
Fixes: regress ssl/bufferevent_socketpair_timeout_freed_fd
2015-09-02 19:20:19 +03:00
Azat Khuzhin
af85ecfccc Merge branch 'test-regress-be-openssl-v2'
This patchset is a bunch of regression tests for bufferevent openssl layer,
some of them already show some bugs, that bugs will be fixed in the next
patches.

* test-regress-be-openssl-v2:
  test/regress_ssl: check events fd/pending after timeout triggered
  test/regress_ssl: cover case when server didn't up (failed with timeout)
  test/regress_ssl: covert that we can't change fd with underlying
  test/regress_ssl: cover that events (read/write) at finish not pending
  test/regress_ssl: cover fd manipulations
  test/regress_ssl: convert open_ssl_bufevs() to mask
  test/regress_ssl: convert client/server to mask too
  test/regress_ssl: cover "allow_dirty_shutdown"
  test/regress_ssl: convert regress_bufferevent_openssl() to bitmask
2015-09-02 19:18:08 +03:00
Azat Khuzhin
cdafdf017e test/regress_ssl: check events fd/pending after timeout triggered
In this case client can't connect to server, and this bring to the front some
bugs with assigning on already added events (because of ```fd_is_set``` stuff),
for more info see #258, since this is the reproducible for it.
2015-09-02 19:15:27 +03:00
Azat Khuzhin
74845f1198 test/regress_ssl: cover case when server didn't up (failed with timeout) 2015-09-02 19:08:36 +03:00
Azat Khuzhin
df507afafd test/regress_ssl: covert that we can't change fd with underlying 2015-09-02 19:07:08 +03:00
Azat Khuzhin
762edb46a8 test/regress_ssl: cover that events (read/write) at finish not pending 2015-09-02 19:06:45 +03:00
Azat Khuzhin
b78a829752 test/regress_ssl: cover fd manipulations 2015-09-02 19:04:52 +03:00
Azat Khuzhin
46bba73103 test/regress_ssl: convert open_ssl_bufevs() to mask 2015-09-02 19:04:45 +03:00
Azat Khuzhin
34559913c0 test/regress_ssl: convert client/server to mask too 2015-09-02 19:04:39 +03:00