BEV_OPT_DEFER_CALLBACKS seems responsible for the issue with srv_dst, libevent acts as if we call event connect() ourselves. See: Launching connections on socket-based bufferevents at http://www.wangafu.net/~nickm/libevent-book/Ref6_bufferevent.html. So enable writecb and assume write event as CONNECTED too.
// @todo Do we really need to defer callbacks? BEV_OPT_DEFER_CALLBACKS seems responsible for the issue with srv_dst: We get writecb sometimes, no eventcb for CONNECTED event
// @attention This does not work, since the listener cb is not finished yet, trying to free the conn causes multithreading issues
// if (bev==ctx->srv_dst.bev) {
// // @attention Sometimes dst write cb fires but not event cb, especially if the listener cb is not finished yet, so the conn stalls. This is a workaround for this error condition, nothing else seems to work.
// @todo Should enable the lines below to workaround eventcb issue? Would it help?
// @todo Should enable the lines below to workaround eventcb issue? Would it help?
// if (bev == ctx->srv_dst.bev && !ctx->srv_dst_connected) {
// @attention Sometimes dst write cb fires but not event cb, especially if the listener cb is not finished yet, so the conn stalls. This is a workaround for this error condition, nothing else seems to work.
log_dbg_level_printf(LOG_DBG_MODE_FINE,">>>>>=================================== pxy_conn_connect: FAILED bufferevent_socket_connect for srv_dst\n");
log_dbg_level_printf(LOG_DBG_MODE_FINE,">>>>>=================================== pxy_conn_connect: FAILED bufferevent_socket_connect for srv_dst\n");
if(ctx->srv_dst.ssl){
// @attention Do not try to close the conn here , otherwise both pxy_conn_connect() and eventcb try to free the conn using pxy_conn_free(),
SSL_free(ctx->srv_dst.ssl);
// they are running on different threads, causing multithreading issues, e.g. signal 10.
ctx->srv_dst.ssl=NULL;
// @todo Should we use thrmgr->mutex? Can we?
}
pxy_conn_free(ctx);
return;
}
}
// @attention Do not do anything else with the ctx after connecting socket, otherwise if pxy_bev_eventcb fires on error, such as due to "No route to host",
// @attention Do not do anything else with the ctx after connecting socket, otherwise if pxy_bev_eventcb fires on error, such as due to "No route to host",