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

Re: [Libevent-users] Segfault under specific conditions



On Wed, Mar 10, 2010 at 4:22 AM, David Titarenco
<david.titarenco@xxxxxxxxx> wrote:
 [...]
> I get my req pointer from an STL map: map<evhttp_request *,bead> that I
> iterate over. Now, I wrote a home-made timeout method that uses evtimer for
> these long-polling connections (that I call beads). The only thing that I'm
> worried about is that the timeout callback might be fired in the middle of a
> (long) iteration in case of many connections (could this even happen? -the

It depends what you mean by an "iteration".  Libevent runs callbacks
one-at-a-time.

> which in turn also closes the connection and
> deletes map entry.

I'm assuming that you've made sure that anything else that frees the
connection will also delete the timeout event too.?

> But if this weird race condition DOES happen, it _should_
> give me an STL null pointer exception, not a libevent segfault. Moreover, is
> there any way to check and see if the req is valid or not, to at least avoid
> a server crash?

Your best bet here is using a tool like valgrind (which should work
with C++) or dmalloc (there is probably a C++ equivalent) to catch the
memory problem.  I agree with niels that it looks like something is
getting freed too early; I'm not sure whether that's your program's
bug or Libevent's, though.

You could also try turning on debug mode for Libevent [with
event_enable_debug_mode(); see the documentation for that function],
which might be able to catch some event-related errors.

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