[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] 100% cpu utilization with openssl bufferevent.



On Thu, Apr 29, 2010 at 2:14 PM, Sebastian Sjöberg
<Sebastian.Sjoberg@xxxxxxxx> wrote:
 [...]
>> If it's the second problem, I'd start by testing whether stuff begins
>> to work when you set the EVENT_NOEPOLL environment variable.  If so,
>> then the bug is probably with the epoll backend -- or at least, it
>> requires the epoll backend to appear.  To debug this, I'd add
>> debugging messages to the loop in epoll_dispatch that calls
>> evmap_io_active to tell me whenever it decided not to call
>> evmap_io_active, and I'd have evmap_io_active tell me whenever it made
>> 0 events become active.
>
> Cheers, I haven't yet been able to reproduce it when disabling epoll.
>
> I've started to debug the evmap_io_active calls and after a while there are a no events being activated as you said so I guess at some point the there's a mismatch between what's in epoll and in the event map.

Hi, Sebastian!  Have you had any luck tracking this down?  I'd really
like to try to get this bug fixed before 2.0 goes into a release
candidate status.

I've looked through the code, and tried to reproduce the behavior
you're seeing, but I haven't been able to figure out where the trouble
is.  I'm attaching a patch that should give a warning assertion
failure when the error condition hits; together with debugging log
output [build libevent with -DDEBUG to get that ], it might be enough
to track the bug down.

Also, is there some code I can run to try to reproduce this bug
myself?  I've tried writing examples with openssl, but I can't make
the warnings trigger.

yrs,
-- 
Nick
From 2a8a0d0a81fda941bb221f04c4bc6e0cd269ab77 Mon Sep 17 00:00:00 2001
From: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue, 18 May 2010 15:22:48 -0400
Subject: [PATCH] Warning statements to catch possible bug in epoll

---
 epoll.c |    5 +++--
 evmap.c |    8 +++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/epoll.c b/epoll.c
index 6c3cf33..32aff2c 100644
--- a/epoll.c
+++ b/epoll.c
@@ -319,8 +319,9 @@ epoll_dispatch(struct event_base *base, struct timeval *tv)
 				ev |= EV_WRITE;
 		}
 
-		if (!events)
-			continue;
+		if (ev == 0) {
+			event_warnx("%s: epoll gave us no actionable events for fd %d!", __func__, events[i].data.fd);
+		}
 
 		evmap_io_active(base, events[i].data.fd, ev | EV_ET);
 	}
diff --git a/evmap.c b/evmap.c
index cb28002..4e4d2e9 100644
--- a/evmap.c
+++ b/evmap.c
@@ -389,6 +389,7 @@ evmap_io_active(struct event_base *base, evutil_socket_t fd, short events)
 	struct event_io_map *io = &base->io;
 	struct evmap_io *ctx;
 	struct event *ev;
+	int n_activated = 0;
 
 #ifndef EVMAP_USE_HT
 	EVUTIL_ASSERT(fd < io->nentries);
@@ -397,8 +398,13 @@ evmap_io_active(struct event_base *base, evutil_socket_t fd, short events)
 
 	EVUTIL_ASSERT(ctx);
 	TAILQ_FOREACH(ev, &ctx->events, ev_io_next) {
-		if (ev->ev_events & events)
+		if (ev->ev_events & events) {
 			event_active_nolock(ev, ev->ev_events & events, 1);
+			++n_activated;
+		}
+	}
+	if (n_activated == 0) {
+		event_warnx("%s: We found no activateable events for fd %d, events %d!", __func__, fd, (int)events);
 	}
 }
 
-- 
1.6.6.1