Unfortunately I do not have 50L sample for this but the stacktrace should
give the clear picture on how this happens.

I solved the problem by moving my shutdown flow (i.e. calls like
bufferevent_disable) into event base main thread which apparently solves
the deadlock bug.


On Thu, Jan 1, 2015 at 7:39 PM, Azat Khuzhin <[email protected]> wrote:

> On Thu, Jan 01, 2015 at 08:46:12AM +0200, Roman Gershman wrote:
> > Hi,
> >
> > I found the following deadlock bug in libevent code (2.0.21). It looks
> that
> > the problem is in
> > bufferevent_disable that locks bufev and transitively calls
> > event_del_internal which waits for read callback to finish when it's not
> in
> > the main thread. Meanwhile the main thread calls bufferevent_readcb which
> > deadlocks on bufev.
> >
> > Is it a known issue? Are there workarounds for this?
>
> Here is the similar issue:
> https://github.com/nmathewson/Libevent/issues/105
>
> And also you could read about new feature in 2.1.x: finalizers
> http://archives.seul.org/libevent/users/Apr-2013/msg00002.html
>
> I guess this must be fixed with finalizers.
> Also if you could post here a ~50L sample I could check it.
>
> >
> > libevent thread:
> >
> > #1  0x00007ffff794e672 in _L_lock_953 () from
> > /lib/x86_64-linux-gnu/libpthread.so.0
> > #2  0x00007ffff794e4da in __GI___pthread_mutex_lock (mutex=0x1031c80) at
> > ../nptl/pthread_mutex_lock.c:114
> > #3  0x00007ffff771723c in _bufferevent_incref_and_lock
> > (bufev=bufev@entry=0x1188c00)
> > at bufferevent.c:582
> > #4  0x00007ffff771842a in bufferevent_readcb (fd=11, event=<optimized
> out>,
> > arg=0x1188c00) at bufferevent_sock.c:133
> > #5  0x00007ffff770df24 in event_process_active_single_queue
> > (activeq=0x1024640, base=0x1090000) at event.c:1350
> >
> >
> > user thread:
> > #0  pthread_cond_wait@@GLIBC_2.3.2 () at
> > ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
> > #1  0x00007ffff74fdfe5 in evthread_posix_cond_wait (_cond=0x1032430,
> > _lock=0x1032460, tv=0x0) at evthread_pthread.c:156
> > #2  0x00007ffff770b9ed in event_del_internal (ev=<optimized out>) at
> > event.c:2220
> > #3  event_del (ev=ev@entry=0x1188c10) at event.c:2188
> > #4  0x00007ffff7718645 in be_socket_disable (bufev=0x1188c00,
> > event=<optimized out>) at bufferevent_sock.c:570
> > #5  0x00007ffff771702b in bufferevent_disable (bufev=0x1188c00,
> > event=<optimized out>) at bufferevent.c:505
> ***********************************************************************
> To unsubscribe, send an e-mail to [email protected] with
> unsubscribe libevent-users    in the body.
>

Reply via email to