Prevent possible multithreading issues, which would not cause crashes but incorrect conn ids and memory leaks due to broken thread conn linked lists

pull/13/head
Soner Tari 6 years ago
parent 3d1ed7c8d2
commit 360b951ade

@ -171,12 +171,6 @@ pxy_conn_ctx_new(evutil_socket_t fd,
}
memset(ctx, 0, sizeof(pxy_conn_ctx_t));
ctx->id = thrmgr->conn_count++;
#if defined (DEBUG_PROXY)
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_conn_ctx_new: id=%llu, fd=%d\n", ctx->id, fd);
#endif /* DEBUG_PROXY */
ctx->type = CONN_TYPE_PARENT;
ctx->fd = fd;
ctx->conn = ctx;
@ -206,11 +200,11 @@ pxy_conn_ctx_new(evutil_socket_t fd,
ctx->ctime = time(NULL);
ctx->atime = ctx->ctime;
ctx->next = NULL;
pxy_thrmgr_attach(ctx);
#ifdef HAVE_LOCAL_PROCINFO
ctx->lproc.pid = -1;
#endif /* HAVE_LOCAL_PROCINFO */

@ -546,6 +546,12 @@ pxy_thrmgr_attach(pxy_conn_ctx_t *ctx)
pxy_thrmgr_ctx_t *tmctx = ctx->thrmgr;
pthread_mutex_lock(&tmctx->mutex);
ctx->id = ctx->thrmgr->conn_count++;
#ifdef DEBUG_PROXY
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_thrmgr_attach: id=%llu, fd=%d\n", ctx->id, ctx->fd);
#endif /* DEBUG_PROXY */
minload = tmctx->thr[thridx]->load;
#ifdef DEBUG_THREAD
log_dbg_printf("===> Proxy connection handler thread status:\n"
@ -565,14 +571,14 @@ pxy_thrmgr_attach(pxy_conn_ctx_t *ctx)
ctx->thr->load++;
ctx->thr->max_load = MAX(ctx->thr->max_load, ctx->thr->load);
ctx->next = ctx->thr->conns;
ctx->thr->conns = ctx;
pthread_mutex_unlock(&tmctx->mutex);
ctx->evbase = ctx->thr->evbase;
ctx->dnsbase = ctx->thr->dnsbase;
ctx->next = ctx->thr->conns;
ctx->thr->conns = ctx;
// @attention We are running on the thrmgr thread, do not call conn thread functions here.
//pxy_thrmgr_print_thr_info(ctx->thr);

Loading…
Cancel
Save