On Thu, Mar 22, 2012 at 07:11:01PM -0300, William Lima wrote: > Hi! > > I'm using bufferevent in my proxy project and I have a bug. The entire > program is single-thread, but apparently the error callback can be called > while something is still running (ie. a parser) into server/client read > callbacks, causing a segmentation fault, since the error callback destroy > the Connection class. > Is it the expected behavior? Should I add a *state* to check when a > callback is running and not delete on error callback directly? > > The related code is listed below (server_error_cb, server_read_cb functions > are similar, but not listed): >
Just glancing over your code, the while loop seems like it may be the cause. When you call bufferevent_write_buffer(), if it is not setup to be deferred, will immediately attempt to write to the underlying socket. If the write call fails for some reason, your error callback is executed. while (1) { bufferevent_write_buffer() { <invoke callbacks on the write event> { bufferevent_sock:writecb { send(sock, ....) <= 0 { bufferevent_run_eventcb(..., BEV_EVENT_[ERROR|EOF]) { Connection::client_error_cb() { } } } } } I would suggest setting BEV_OPT_DEFER_CALLBACKS when creating your bufferevents if you're using it like this. Hope it helps! *********************************************************************** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body.