423 Commits

Author SHA1 Message Date
Nicholas Marriott
88640aa1ca event_reinit: make signals works after fork() without evsig_add()
event_reinit() removes the event, but only evsig_add puts it back. So any
signals set up before event_reinit will be ignored until another signal is
added.

Fixes: #307
2015-12-27 02:51:43 +03:00
Nicholas Marriott
ad0c237bc0 event_reinit: always re-init signal's socketpair
Before this patch event_reinit() only closes the signal socketpair fds and
recreates them if signals have been added, but this is wrong, since socketpair
fds created on backend init, and if we will not re-create them bad things in
child/parent signal handling will happens (and indeed this is what happens for
non-reinit backends like select).

Fixes: #307
2015-12-27 02:51:24 +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
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
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
Mark Ellzey
dcfb19a27b Debug mode option to error on evthread init AFTER other event calls.
- A handy event_enable_debug_mode() feature which will error and abort the
  application if any thread-aware libevent functions are called BEFORE the
  evthread API has been initialized (manually, or through
  evthread_use_windows_threads() / evthread_use_pthreads()

- This is done by setting the global debug variable
  'event_debug_created_threadable_ctx_' whenever the following functions
  are called:

     evthreadimpl_lock_alloc_()
     evthreadimpl_cond_alloc_()
     event_base_new_with_config() <- this checks to see if the thread
                                     callbacks are enabled first, so we
                                     have to manually set the variable.

- Example:

int main(int argc, char ** argv) {
    struct event_base * base;

    event_enable_debug_mode();

    base = event_base_new();

    evthread_use_pthreads();

    return 0;
}

When executed, the program will throw an error and exit:

[err] evthread initialization must be called BEFORE anything else!
2015-05-15 02:58:14 -07:00
Greg Hazel
6e7a580c15 tab 2015-03-24 17:45:52 -07:00
Greg Hazel
38cef641c4 fix the return value of event_deferred_cb_schedule_ 2015-03-24 17:29:40 -07:00
Nick Mathewson
a77a82a03f Merge remote-tracking branch 'azat/be-pair-fix-freeing-shared-lock-v5' 2015-02-04 08:37:32 -05:00
Azat Khuzhin
e5c87d18b0 event_free_debug_globals_locks(): disable lock debugging
This will allow to use library event after
event_free_debug_globals_locks()/libevent_global_shutdown() without
invalid read/write's.
2015-01-26 00:40:09 +03:00
Azat Khuzhin
941faaed39 event: call event_disable_debug_mode() in libevent_global_shutdown()
This will avoid leaking of event_debug_map_HT_GROW

I buildin it into libevent_glboal_shutdown() because
event_disable_debug_mode() -> event_free_debug_globals() ->
event_free_debug_globals_locks() will clean event_debug_map_lock_ that
used in event_disable_debug_mode().
2015-01-08 04:49:28 +03:00
Andrea Shepard
f2645f80c1 Implement new/free for struct evutil_monotonic_timer and export monotonic time functions 2014-12-04 09:30:20 -05:00
Nick Mathewson
37145c5659 Merge remote-tracking branch 'public/patches-2.0'
Conflicts:
	ChangeLog
	event.c
2014-11-30 21:07:55 -05:00
vjpai
3c7d6fcaff Fix race caused by event_active
There is a race between manual event_active and natural event activation. If both happen at the same time on the same FD, they would both be protected by the same event base lock except for 1 LoC where the fields of struct event are read without any kind of lock. This commit does those reads into local variables inside the lock and then invokes the callback with those local arguments outside the lock. In 2.0-stable, none of this is inside the lock; in HEAD, only the callback is read inside the lock. This gets the callback and all 3 arguments inside the lock before calling it outside the lock.
2014-11-30 19:24:15 -05:00
John Ohl
3cc0eace2e Fix use-after-free error in EV_CLOSURE_EVENT callback 2014-09-18 11:37:28 -04:00
Nick Mathewson
ec99dd82e4 Fix a use-after-free error on EV_CLOSURE_EVENT_FINALIZE callbacks
After running the callback, we were checking evcb->evcb_closure to
decide whether to call mm_free(ev).  But the callback itself might
have freed ev, so we need to grab that field first

Found with AddressSanitizer
2014-03-18 11:27:08 -04:00
Nick Mathewson
980597215d Move assert(ev) to before we use ev in EV_CLOSURE_EVENT_FINALIZE case
Based on a patch from Harlan Stenn.
2014-03-06 10:09:03 -05:00
John Ohl
2ea15ed0f6 Tweaked callbacks to prevent race condition (https://github.com/libevent/libevent/issues/104) 2014-01-27 14:54:55 -05:00
John Ohl
40830f1644 Tweaked callbacks to prevent race condition (https://github.com/libevent/libevent/issues/104) 2014-01-27 13:03:36 -05:00
Diego Giagio
b1b69ac7c1 Implemented EV_CLOSED event for epoll backend (EPOLLRDHUP).
- Added new EV_CLOSED event - detects premature connection close
  by clients without the necessity of reading all the pending
  data. Does not depend on EV_READ and/or EV_WRITE.

- Added new EV_FEATURE_EARLY_CLOSED feature for epoll.
  Must be supported for listening to EV_CLOSED event.

- Added new regression test: test-closed.c

- All regression tests passed (test/regress and test/test.sh)

- strace output of test-closed using EV_CLOSED:
    socketpair(PF_LOCAL, SOCK_STREAM, 0, [6, 7]) = 0
    sendto(6, "test string\0", 12, 0, NULL, 0) = 12
    shutdown(6, SHUT_WR)                    = 0
    epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0
    epoll_wait(3, {{EPOLLRDHUP, {u32=7, u64=7}}}, 32, 3000) = 1
    epoll_ctl(3, EPOLL_CTL_MOD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0
    fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...})
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYM...
    write(1, "closed_cb: detected connection close "..., 45) = 45
2014-01-17 23:20:42 -02:00
Nick Mathewson
f9e091bf4e Merge remote-tracking branch 'asweeny86/event-count-max' 2014-01-06 12:11:30 -05:00
Andrew Sweeney
efbd3dcf28 Fixed bug using wrong variable in max event compare 2014-01-05 16:29:52 -05:00
Andrew Sweeney
5173bef50f Add access to max event count stats
This commit provides an interface for accessing and resetting the maximum
number of events in a given period.  This information provides better insight
into event queue pressure.
2013-12-30 14:06:20 -05:00
Nick Mathewson
87fa2b004a Unit tests for active_by_fd; unsupport active_by_fd(TIMEOUT)
[It turns out that event_base_active_by_fd(TIMEOUT) didn't actually
work right. Feel free to add it back in as a patch.]
2013-12-23 20:46:38 -05:00
Nick Mathewson
486594337a Add event_base_active_by_signal by analogy 2013-12-21 23:32:10 -05:00
Nick Mathewson
5c9da9a8a8 Sanity-check arguments to event_base_active_by_fd() 2013-12-21 23:21:33 -05:00
Nick Mathewson
93369ff4e9 Merge remote-tracking branch 'ghazel/event_base_active_by_fd' 2013-12-21 23:15:41 -05:00
Nick Mathewson
1c06985a01 Add an assertion for another of the complaints from coverity. See 1b065d07df196 2013-08-06 20:00:53 -04:00
Nick Mathewson
69b5c64704 Move event_debug_note_teardown_ before mm_free.
This isn't a bug, since only the pointer value of ev was used, but
it's probably best not to tempt fate.  Found by coverity.
2013-08-06 19:10:13 -04:00
Nick Mathewson
1b065d07df Add some assertions to please coverity.
In event_process_active_single_queue, EVLIST_INIT must be set on any
event that uses one of the event-only closures, and so "ev" will be
set in those cases.  But coverity's worried here (CIDs numerous).  So
instead, just add the assertions that should make it happy.
2013-08-06 19:10:13 -04:00
Mobai Zhang
0fa107d8cb Added event_base_get_num_events() 2013-07-02 16:01:02 -04:00
Nick Mathewson
3dc2d8ab83 Remove a debugging assert that should not have been left in 2013-05-28 10:14:51 -04:00
Azat Khuzhin
d3d999a116 Missed lock acquire/release in event_base_cancel_single_callback_()
Call backtrace:
...
event_queue_remove_active()
event_callback_cancel_nolock_()
event_base_cancel_single_callback_()
event_base_free_()
event_base_free()
...

Fix for e9ebef83
2013-05-10 21:40:45 -04:00
Nick Mathewson
f2925d78b6 Fix a windows compilation regression
This is github issue #57; reported by "efekty". I assume the compiler
is MSVC.
2013-04-30 22:57:25 -04:00
Nick Mathewson
3555befd1c Merge branch '21_deadlock_fix_v2' 2013-04-26 12:27:05 -04:00
Nick Mathewson
5d11f4f39a Make the event_finalize* functions return an error code 2013-04-26 12:18:38 -04:00
Nick Mathewson
a800b913ac More documentation for finalization feature 2013-04-26 12:18:38 -04:00
Nick Mathewson
e9ebef83a0 Always run pending finalizers when event_base_free() is called
There was actually a bug in the original version of this: it tried to
run the finalizers after (potentially) setting current_base to NULL;
but those finalizers could themselves (potentially) be invoking stuff
that needed to know about the current event_base.  So the right time to
do it is _before_ clearing current_base.
2013-04-26 12:18:07 -04:00
Nick Mathewson
8eedeabe50 Implement event_finalize() and related functions to avoid certain deadlocks 2013-04-26 12:18:07 -04:00
Nick Mathewson
5e6fa2a3ab event_base_update_cache_time should be a no-op if the loop isn't running 2013-04-24 13:23:15 -04:00
Nate Rosenblum
9443868d55 Double-check next timeout when adding events
When resuming the system from a suspended state, the ev_timeout field
of a scheduled timer event may be in the past. This leads to
unexpected behavior when scheduling a short-duration timer event
immediately after returning from suspension, because the new event
does not land on top of the timeout minheap and so the event loop
(blocked on a possibly long-duration timeout) is not notified.

This patch checks for this condition and, if it obtains, notifies the
event loop.
2013-03-05 11:29:33 -08:00
Patrick Pelletier
0c6ec5d816 use FormatMessage for winsock errors
as discussed here:
http://archives.seul.org/libevent/users/Feb-2013/msg00004.html
2013-02-14 20:26:38 -08:00
Nick Mathewson
5623e80371 Make event_remove_timer behave correctly with persistent timers 2013-02-13 11:41:11 -05:00
Greg Hazel
865a14261c event_base_active_by_fd 2013-01-16 16:31:08 -08:00
Nick Mathewson
bf7a0ff268 When EWOULDBLOCK is not EAGAIN, treat it as equivalent to it
Acording to http://stackoverflow.com/questions/7003234/which-systems-define-eagain-and-ewouldblock-as-different-values
there are some older unixes that distinguish these error.s
2013-01-11 16:37:34 -08:00
Nick Mathewson
f2703b2e34 Fix a warning when building without threading. 2012-11-18 01:40:13 -05:00
Nick Mathewson
e3b2e0869e Add an event_remove_timer() to remove timer on an event without deleting it 2012-11-16 16:43:17 -05:00
Nick Mathewson
1fda492878 Merge remote-tracking branch 'origin/patches-2.0' 2012-11-16 12:06:40 -05:00
Nick Mathewson
e3cccf380c Avoid crash when event_pending() called with no event_base set on event
Instead, give a warning and return 0.

Reported by Antony Dovgal on github as
   https://github.com/libevent/libevent/issues/19
2012-11-16 11:56:56 -05:00
Nick Mathewson
c17dd59191 Free dangling event_once objects on event_base_free()
This patch makes us keep event_once objects in a doubly linked list
so we can free any once that haven't triggered when we call
event_base_free().
2012-11-16 10:05:04 -05:00