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

Re: [Libevent-users] Event loop not exiting when freeing bufferevent



On Tue, Dec 29, 2009 at 12:39:30PM +0100, Bas Verhoeven wrote:
> Nick Mathewson wrote:
> >It's supposed to work like that, yes. My guess would be that either
> >there's a bug in your code, or that you've found a bug in Libevent.
> >
> >To narrow it down, can you write a short test program that displays
> >the problematic behavior?  I've tried to do one myself, but I can't
> >get the behavior you're seeing: for me, disabling the last bufferevent
> >does indeed exit the loop.
> >  
> Hi, thanks for your response.
> 
> I guess I was wrong - this isn't related to bufferevents at all. I've 
> written a small application that simply initializes libevent & evdns and 
> starts the loop:
> 
> int main(int argc, char **argv)
> {
>    struct event_base *base;
>    struct evdns_base *dns_base;
> 
>    if ((base = event_base_new()) == NULL)
>    {
>        return 0;
>    }
> 
>    printf("Initialized libevent (method %s)\n", 
> event_base_get_method(base));
> 
>    if (argc == 2 && !strcmp(argv[1], "--dns"))
>    {
>        if ((dns_base = evdns_base_new(base, 1)) == NULL)
>        {
>            return 0;
>        }
> 
>        printf("Initialized evdns..\n");
>    }
> 
>    printf("Starting event loop..\n");
> 
>    event_base_loop(base, 0);
> 
>    printf("Event loop ended..\n");
>    return 0;
> }
> 
> I've found that not loading evdns will cause the loop to exit 
> immediately. Simply loading evdns is enough to keep the event loop running:
> 
> dev@blackbox:~$ ./evtest
> Initialized libevent (method epoll)
> Starting event loop..
> Event loop ended..
> 
> dev@blackbox:~$ ./evtest --dns
> Initialized libevent (method epoll)
> Initialized evdns..
> Starting event loop..
> ^C
> 
> Apparently evdns has its own event in the event loop causing libevent to 
> keep the event loop alive, or something along those lines, which 
> explains the issue I'm seeing?

This is so; evdns currently listens for replies from the
nameserver(s), and the events that do this will keep the loop running
until you exit it with event_base_loopexit() or until you shut down
the evdns base with evdns_base_free().

I've thought it might be nice to have a user-visible concept of
"events that don't prevent event_base from exiting", analogous to the
idea many threading libraries have of "threads that don't prevent the
process from exiting".  There's a feature proposal here:
https://sourceforge.net/tracker/?func=detail&aid=2897822&group_id=50884&atid=461325
.  The last time we spoke about it, Niels didn't much like the idea,
though.

yrs,
-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.