vijay mishra | 9 May 10:43 2016

Re: Re: Regarding broken connection when using libevent with redsocks in android M OS

Hi Azat,
   The problem is seen with libevent version 2-1-5 also.
Actually in bufferevent_ratelim.c, we are using MAX_TO_READ_EVER &  MAX_TO_WRITE_EVER buffer sizes set to 16387.

When we try to use bigger buffer sizes here... Say 32MB or 16 MB,  we are facing the issue that playstore start - stop-start hangs the whole data connection. Even other applications are not able to use redsocks new clients.

But with lesser values as is there by default -  16387,this issue is not seen. But the internet speed will be lesser. We are using higher values so as to get higher speeds (better throughput).

Our understanding is that due to these high values of buffersizes, libevent is getting stuck somewhere.

Can you point us to what might the problem area be?


On 9 May 2016 04:51, "Azat Khuzhin" <a3at.mail <at>> wrote:
On Sat, May 07, 2016 at 02:08:35PM +0530, vijay mishra wrote:
> Dear All,
> In attempt to fix this problem, we ported the latest libevent beta release
> (2-1-15, beta release) and with that , this issue is resolved but we are


I guess you meant *2.1.5*?

> not able to find which exact commit in the latest libevent might be solving
> this issue
> Can anyone here help us identify the commit which may have had this issue
> fixed.
> PS: in stable release version 2-0-22,the issue was seen. So we suspect some
> commit after that is fixing this issue.

There are a lot of changes between 2.0.22 and 2.1.5, and I'm not even
sure because of which layer this can be, maybe you can do some

To unsubscribe, send an e-mail to majordomo <at> with
unsubscribe libevent-users    in the body.
vijay mishra | 7 May 04:04 2016

Regarding broken connection when using libevent with redsocks in android M OS

Hi All.

  I was wondering if anyone here has tried libevent/redsocks combinatin in android latest versions.
We were using redsocks + libevent for data redirection to our proxy in Android L version but since we have moved to android M version we are getting a very strange issue.

   The problem is that when we install-stop-install-stop in the playstore, the device gets stuck, and NO applications can use data further.

 The reason is that we are not seeing the event generated from libevent for redsocks to read any new client connection once we do that insall-stop-install.

we are using libevent 2-0-22 stable release, but we have seen this issue  using previous libevent versions(2-0-21)  also.

 Looks like some read/write event issue in libevent.

Please help if someone has seen such behaviour in other cases also

Akhilesh Shukla | 20 Apr 07:53 2016

libevent conflict on Centos6.7


I have nfs-utils installed on system which has dependancy on libevent 1.4 , now with new requirement I need to install pgbouncer1.7 which have depdendancy on libevent-2.x version. Centos 6.7 updates doesn't have the libevent-2.x version publish. Its only available with Centos7. 

Is there any support issue with libevent-2.x on version lower that Centos7 ? 

To resolve this I am looking for below two appraoches:

1.  Build libevent-2.x version on centos 6.7 and upgrade to libevent-2.x version on my system.

     Do you see any issues while using libevent-2 with centos6.7 ?

2. Use libevent-1.4 and libevent-2.x in parallel by rebuilding and renaming libevent-2.x as     
     It looks like the source files are different names for both libevent version and should not be a problem if i use both version together on by system.


Akhilesh Kumar Shukla

Jan Heylen | 18 Apr 16:34 2016

pkgconfig libevent_core


is there a reason has no pkg-config file generated in (like libevent.pc, libevent_pthreads.pc,

best regards,

To unsubscribe, send an e-mail to majordomo <at> with
unsubscribe libevent-users    in the body.

vijay mishra | 8 Apr 13:51 2016

Regarding Libevent Crash Issue

Dear Lib-event enthusiasts, 

I am a beginner and I am using libevent with redsocks.

 Actually we are struggling with a crash in libevent.
  I was wondering if that is already reported to soem of you guys and someone have some fix for the same . It will be a great hep if you can suggest some solutions to this crash.

The details of this crash are as below :-

Crash type as seen in the Logs

signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7fa2cd2210

AM write failed: Broken pipe

Using debug symbols we were able to get the stack trace of the function calls. The stack trace for this issue is as below :-






As we can see from above that the problem lies with evbuffer_run_callbacks() function at line 486, I am pasting the function code snippet below with the Problem Line => highlighted

Code Snippet:

static void
evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred)
struct evbuffer_cb_entry *cbent, *next;
struct evbuffer_cb_info info;
size_t new_size;
ev_uint32_t mask, masked_val;
int clear = 1;

if (running_deferred) {
} else if (buffer->deferred_cbs) {
/* Don't zero-out n_add/n_del, since the deferred callbacks
   will want to see them. */
clear = 0;
} else {


if (TAILQ_EMPTY(&buffer->callbacks)) {
buffer->n_add_for_cb = buffer->n_del_for_cb = 0;
if (buffer->n_add_for_cb == 0 && buffer->n_del_for_cb == 0)

new_size = buffer->total_len;
info.orig_size = new_size + buffer->n_del_for_cb - buffer->n_add_for_cb;
info.n_added = buffer->n_add_for_cb;
info.n_deleted = buffer->n_del_for_cb;
if (clear) {
buffer->n_add_for_cb = 0;
buffer->n_del_for_cb = 0;
for (cbent = TAILQ_FIRST(&buffer->callbacks);
     cbent != TAILQ_END(&buffer->callbacks);
     cbent = next) {
/* Get the 'next' pointer now in case this callback decides
 * to remove itself or something. */
next = TAILQ_NEXT(cbent, next);

if ((cbent->flags & mask) != masked_val)

if ((cbent->flags & EVBUFFER_CB_OBSOLETE))
Problem Line => cbent->cb.cb_obsolete(buffer,
    info.orig_size, new_size, cbent->cbarg);
cbent->cb.cb_func(buffer, &info, cbent->cbarg);

It will a great help if anyone of you can suggest a solution from your previous experience(if already encountered such a problem)  or from your expertise.

Thanks and Regards
enggatwork(Vijay Mishra)
Tim Chou | 23 Mar 23:31 2016

Add multiples bufferevents on one base then lead to some errors.

Hi all,

Sorry to disturb you. 
I'm writing a server. I plan to use one thread serving ten connections.
I use bufferevent_setcb to register 10 sockets to one base. I also use a global variable to count the number.

I think I can register the bufferevent on one base before I start a pthread to dispatch().
However, I always get the error: [err] event_queue_insert: 0x146dfc8(fd 32) already on queue 2

If I create one thread for one base with only one bufferevent, then the program works well.

Does anyone help me?
Looking forward to your replies.


Below is my code. 


  if (num_dist==0) {
  /* Create a buffer event. */
  bev = malloc(sizeof(struct bufferevent));
  bev = bufferevent_socket_new(evbase, client_fd, BEV_OPT_CLOSE_ON_FREE);

  bufferevent_setcb(bev, buffered_on_read, buffered_on_write, NULL, NULL);

  bufferevent_enable(bev, EV_READ|EV_WRITE|EV_PERSIST);

  if (num_dist==10) {
  printf("%d thread creates.\n",total_thread);
  pthread_create(&tid, NULL, &server_job_function, (void *) evbase);

Michael | 20 Mar 15:54 2016

Handling the connection close

Hi all,

I want to ask what should I do when the connection is closed while I am 
sending or recving data. For example the connection is closed by the 
server explicitly or because the server is down, when the client is 
still sending data or recving data. For libevent, if the connection is 
closed, event callback is invoked. But in this callback what should we 
do? Is there any common practice?

(Any useful code can be directly filled in the following function)


void Connection::EventCb(struct bufferevent *bev, short events, void *ctx) {

     Connection* conn = (Connection*)ctx;
     assert(conn != NULL && bev != NULL);

     if (events & BEV_EVENT_ERROR) {

         LOG_TRACE("Error from client bufferevent: 

         // tell the client send error, and the client should send again 
or do some other things
         if (conn->GetStatus() == SENDING) {
             LOG_TRACE("Send error");
             // TODO: let the client know


     // The other side explicitly closes the connection
     if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {

         // This means server explicitly closes the connection
%s",evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR())); // the error 
string is "SUCCESS"

         // free the buffer event
To unsubscribe, send an e-mail to majordomo <at> with
unsubscribe libevent-users    in the body.

Jan Heylen | 20 Mar 10:58 2016

deferred callbacks and evbuffer cleanup_cb


I'm trying to use evbuffers, cleanup_cb, and the deferred callbacks.

some background:
* using (tcp) sockets
* sending data over the socket: in first place try to write
(evbuffer_write), if you get 'wouldblock' postpone the write by using
bufferevent_write_buffer. Main reason is we don't need to keep the
user's data in most cases and the dat is send immediatly.
* after sending data, a 'send cb' should be called to the user who
wanted to send something.

Now, when looking at the best way to get the cleanup happening (and a
mechanism to let the user know his data is send), I was looking at
both evbuffer callbacks and the evbuffer cleanup_cb.
I'm thinking on using the cleanup_cb, as it is only called when the
chain, the actual data, gets freed, so I can be sure the data is out.
With evbuffer callbacks, the original evbuffer gets drained upon call
to bufferevent_write_buffer already, and not when the data itself is
really 'out', so that means, I have to make a distinction.

However, If I look at the code, these cleanup_cbs are not and cannot
be 'deferred'. So in the first place, when using evbuffer_write, the
cleanup_cb will happen on the stack, and so also my 'data is send'
callback, would happen on stack (and so cb will happen before the
sending data function returns).

* thinking about the 2 different paths on getting data out,
(evbuffer_write and postponed via bufferevent_write_buffer), what
would be the best mechanism to get the 'all data is out' cb mechanism
working for them both?
* Is it a design choice to not defer the cleanup_cb, or would it make
sense to add it?

kind regards,

Jan Heylen
To unsubscribe, send an e-mail to majordomo <at> with
unsubscribe libevent-users    in the body.

Michael | 15 Mar 16:57 2016


Hi All,

This is Michael from CMU. I am currently using libevent in our database 
system ( to let the cluster nodes 
to communicate with each other.

I want to ask how can I use multiple std::threads  on the same 
event_base. For example, a server has a  event_base. When a new 
connection coming, the server creates a std::thread with a socket_event, 
and puts the socket_event into the event_base. If there are ten 
connections, there are ten std::threads sharing the same event_base. 
(Each threads has it own socket_event to recv and send data).

Can I implement that? Is there an example?

I appreciate your help!

To unsubscribe, send an e-mail to majordomo <at> with
unsubscribe libevent-users    in the body.

Himanshu S | 10 Mar 01:07 2016

bufferevent_priority_set() for read/write

Hello experts,

I see there is priority set available for bufferevent using bufferevent_priority_set(). I believe this will set priority for read as well as write events. What I would like to do is prioritize one over another. How do I achieve that?  For eg, I would like to prioritize write over reads or the other way round. Is it possible to do that? 

Simon Perreault | 28 Feb 22:49 2016

[PATCH] Fix filter bufferevent output reentrantness

Make the code do what the comment says it should do.
 bufferevent_filter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bufferevent_filter.c b/bufferevent_filter.c
index 6c3ffc4..5d5f992 100644
--- a/bufferevent_filter.c
+++ b/bufferevent_filter.c
 <at>  <at>  -345,7 +345,8  <at>  <at>  be_filter_process_output(struct bufferevent_filtered *bevf,

 	/* disable the callback that calls this function
 	   when the user adds to the output buffer. */
-	evbuffer_cb_set_flags(bufev->output, bevf->outbuf_cb, 0);
+	evbuffer_cb_clear_flags(bufev->output, bevf->outbuf_cb,

 	do {
 		int processed = 0;


To unsubscribe, send an e-mail to majordomo <at> with
unsubscribe libevent-users    in the body.