From 36075d4de78cb562b0e7a8bea85c868251f0e961 Mon Sep 17 00:00:00 2001 From: Zhang Huan Date: Wed, 24 Jan 2018 16:06:08 +0800 Subject: rpc: fix missing unref on reconnect On protocol client connecting to brick, client will firstly contact glusterd to get port, then reconnect to glusterfsd. Reconnect cancels the reconnect timer and start a new one. However, cancelling the timer does not unref rpc ref-ed for it. That leads to refcount leak. Fix this issue by unref-ing rpc if reconnect timer is canceled. Change-Id: Ice89dcd93cb283a0c7250c369cc8961d52fb2022 Fixes: bz#1538900 BUG: 1538900 Signed-off-by: Zhang Huan --- rpc/rpc-lib/src/rpc-clnt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'rpc') diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c index aa65a1f8766..dac707664df 100644 --- a/rpc/rpc-lib/src/rpc-clnt.c +++ b/rpc/rpc-lib/src/rpc-clnt.c @@ -376,19 +376,20 @@ rpc_clnt_reconnect(void *conn_ptr) struct timespec ts = {0, 0}; struct rpc_clnt *clnt = NULL; gf_boolean_t need_unref = _gf_false; + gf_boolean_t canceled_unref = _gf_false; conn = conn_ptr; clnt = conn->rpc_clnt; - pthread_mutex_lock(&conn->lock); { trans = conn->trans; - if (!trans) { - pthread_mutex_unlock(&conn->lock); - return; + if (!trans) + goto out_unlock; + + if (conn->reconnect) { + if (!gf_timer_call_cancel(clnt->ctx, conn->reconnect)) + canceled_unref = _gf_true; } - if (conn->reconnect) - gf_timer_call_cancel(clnt->ctx, conn->reconnect); conn->reconnect = 0; if ((conn->connected == 0) && !clnt->disabled) { @@ -409,11 +410,14 @@ rpc_clnt_reconnect(void *conn_ptr) gf_log(conn->name, GF_LOG_TRACE, "breaking reconnect chain"); } } +out_unlock: pthread_mutex_unlock(&conn->lock); rpc_clnt_unref(clnt); if (need_unref) rpc_clnt_unref(clnt); + if (canceled_unref) + rpc_clnt_unref(clnt); return; } -- cgit