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

Re: [Libevent-users] Deadlock when calling bufferevent_free from an other thread



On Wed, Aug 8, 2012 at 11:52 AM, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
> On Mon, Aug 6, 2012 at 2:42 PM, Matthieu Nottale
> <mnottale@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>> Hi.
>>
>> I'm experiencing a deadlock on 2.0.19 while calling bufferevent_free frome
>> thread A, while thread B is in event_base_dispatch.
>>
>
> Ouch.  This is a known bug.  This fix is going to be hard.  I wrote
> about it here:
> http://archives.seul.org/libevent/users/Feb-2012/msg00053.html

This is a pretty scary bug, and trivial to hit. Here are my stack traces:

(gdb) bt
#0  __lll_lock_wait () at
../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:132
#1  0x00007ffff7bc7080 in _L_lock_903 () from
/lib/x86_64-linux-gnu/libpthread.so.0
#2  0x00007ffff7bc6f19 in __pthread_mutex_lock (mutex=0x7fffb4000e90)
at pthread_mutex_lock.c:82
#3  0x00000000007e9948 in _bufferevent_incref_and_lock ()
#4  0x00000000007f9b7b in be_openssl_writeeventcb (fd=<optimized out>,
what=4, ptr=0x7fffb400a640) at bufferevent_openssl.c:933
#5  0x00000000007e5920 in event_base_loop ()

(gdb) bt
#0  pthread_cond_wait@@GLIBC_2.3.2 () at
../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:162
#1  0x00000000009cf835 in evthread_posix_cond_wait ()
#2  0x00000000007e420f in event_del ()
#3  0x00000000007f3495 in evbuffer_run_callbacks ()
#4  0x00000000007f5c9f in evbuffer_add ()
#5  0x00000000007e94c0 in bufferevent_write ()

What's interesting is that this only happens if I use a socket based
bufferevent_openssl. With a filtered openssl bufferevent, I don't hit
this deadlock.

Also note that I'm not calling bufferevent_free anywhere -- this is
just the standard pattern a single writer thread (different than the
thread that is running the event loop) is calling bufferevent_write.

Diwaker
-- 
http://maginatics.com
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.