Blob Blame History Raw
From ebf9595432d81d3fb75935360b80e62b4db7644c Mon Sep 17 00:00:00 2001
From: Rajesh Joseph <rjoseph@redhat.com>
Date: Thu, 5 Jan 2017 23:58:21 +0530
Subject: [PATCH 285/285] socket: GF_REF_PUT should be called outside lock

GF_REF_PUT was called inside lock which can call
socket_poller_mayday which inturn tries to take the
same lock. This can lead to deadlock scenario.

>Reviewed-on: https://review.gluster.org/16343
>Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>

BUG: 1409563
Change-Id: Ib3b161bcfeac810bd3593dc04c10ef984f996b17
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/96941
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 rpc/rpc-transport/socket/src/socket.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 7314047..3f7592c 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -2431,7 +2431,6 @@ socket_poller (void *ctx)
          * conditionally
          */
         THIS = this->xl;
-        GF_REF_GET (priv);
 
         if (priv->ot_state == OT_PLEASE_DIE) {
                 gf_log (this->name, GF_LOG_DEBUG, "socket_poller is exiting "
@@ -2624,6 +2623,8 @@ socket_spawn (rpc_transport_t *this)
         gf_log (this->name, GF_LOG_TRACE,
                 "spawning %p with gen %u", this, priv->ot_gen);
 
+        GF_REF_GET (priv);
+
         /* Create thread after enable detach flag */
 
         ret = gf_thread_create_detached (&priv->thread, socket_poller, this);
@@ -2881,9 +2882,10 @@ socket_disconnect (rpc_transport_t *this, gf_boolean_t wait)
         priv = this->private;
 
         if (wait && priv->own_thread) {
+                GF_REF_PUT (priv);
+
                 pthread_mutex_lock (&priv->cond_lock);
                 {
-                        GF_REF_PUT (priv);
                         /* Change the state to OT_PLEASE_DIE so that
                          * socket_poller can exit. */
                         priv->ot_state = OT_PLEASE_DIE;
-- 
2.9.3