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

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



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?
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.