f338ef
From f40570f2f784dc61edb061a4931dcfc16bf51e7e Mon Sep 17 00:00:00 2001
f338ef
From: Aravinda VK <avishwan@redhat.com>
f338ef
Date: Mon, 5 Aug 2019 19:00:21 +0530
f338ef
Subject: [PATCH 277/284] geo-rep: Fix Config Get Race
f338ef
f338ef
When two threads(sync jobs) in Geo-rep worker calls `gconf.get` and
f338ef
`gconf.getr`(realtime) at the sametime, `getr` resets the conf object
f338ef
and other one gets None. Thread Lock is introduced to fix the issue.
f338ef
f338ef
```
f338ef
  File "/usr/libexec/glusterfs/python/syncdaemon/syncdutils.py",
f338ef
  line 368, in twrap
f338ef
    tf(*aargs)
f338ef
  File "/usr/libexec/glusterfs/python/syncdaemon/master.py", line 1987,
f338ef
  in syncjob
f338ef
    po = self.sync_engine(pb, self.log_err)
f338ef
  File "/usr/libexec/glusterfs/python/syncdaemon/resource.py",
f338ef
  line 1444, in rsync
f338ef
    rconf.ssh_ctl_args + \
f338ef
AttributeError: 'NoneType' object has no attribute 'split'
f338ef
```
f338ef
f338ef
Backport of:
f338ef
 > Patch: https://review.gluster.org/#/c/glusterfs/+/23158/
f338ef
 > Change-Id: I9c245e5c36338265354e158f5baa32b119eb2da5
f338ef
 > Updates: bz#1737484
f338ef
 > Signed-off-by: Aravinda VK <avishwan@redhat.com>
f338ef
f338ef
Change-Id: I9c245e5c36338265354e158f5baa32b119eb2da5
f338ef
BUG: 1729915
f338ef
Signed-off-by: Kotresh HR <khiremat@redhat.com>
f338ef
Reviewed-on: https://code.engineering.redhat.com/gerrit/178960
f338ef
Tested-by: RHGS Build Bot <nigelb@redhat.com>
f338ef
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
f338ef
---
f338ef
 geo-replication/syncdaemon/gsyncdconfig.py | 27 +++++++++++++++++++++------
f338ef
 1 file changed, 21 insertions(+), 6 deletions(-)
f338ef
f338ef
diff --git a/geo-replication/syncdaemon/gsyncdconfig.py b/geo-replication/syncdaemon/gsyncdconfig.py
f338ef
index 1fc451f..38f3594 100644
f338ef
--- a/geo-replication/syncdaemon/gsyncdconfig.py
f338ef
+++ b/geo-replication/syncdaemon/gsyncdconfig.py
f338ef
@@ -17,6 +17,7 @@ import os
f338ef
 import shutil
f338ef
 from string import Template
f338ef
 from datetime import datetime
f338ef
+from threading import Lock
f338ef
 
f338ef
 
f338ef
 # Global object which can be used in other modules
f338ef
@@ -35,6 +36,7 @@ class GconfInvalidValue(Exception):
f338ef
 class Gconf(object):
f338ef
     def __init__(self, default_conf_file, custom_conf_file=None,
f338ef
                  args={}, extra_tmpl_args={}, override_from_args=False):
f338ef
+        self.lock = Lock()
f338ef
         self.default_conf_file = default_conf_file
f338ef
         self.custom_conf_file = custom_conf_file
f338ef
         self.tmp_conf_file = None
f338ef
@@ -163,6 +165,11 @@ class Gconf(object):
f338ef
         if value is not None and not self._is_valid_value(name, value):
f338ef
             raise GconfInvalidValue()
f338ef
 
f338ef
+
f338ef
+    def _load_with_lock(self):
f338ef
+        with self.lock:
f338ef
+            self._load()
f338ef
+
f338ef
     def _load(self):
f338ef
         self.gconf = {}
f338ef
         self.template_conf = []
f338ef
@@ -230,12 +237,19 @@ class Gconf(object):
f338ef
         self._tmpl_substitute()
f338ef
         self._do_typecast()
f338ef
 
f338ef
-    def reload(self):
f338ef
+    def reload(self, with_lock=True):
f338ef
         if self._is_config_changed():
f338ef
-            self._load()
f338ef
+            if with_lock:
f338ef
+                self._load_with_lock()
f338ef
+            else:
f338ef
+                self._load()
f338ef
 
f338ef
-    def get(self, name, default_value=None):
f338ef
-        return self.gconf.get(name, default_value)
f338ef
+    def get(self, name, default_value=None, with_lock=True):
f338ef
+        if with_lock:
f338ef
+            with self.lock:
f338ef
+                return self.gconf.get(name, default_value)
f338ef
+        else:
f338ef
+            return self.gconf.get(name, default_value)
f338ef
 
f338ef
     def getall(self, show_defaults=False, show_non_configurable=False):
f338ef
         cnf = {}
f338ef
@@ -276,8 +290,9 @@ class Gconf(object):
f338ef
         return cnf
f338ef
 
f338ef
     def getr(self, name, default_value=None):
f338ef
-        self.reload()
f338ef
-        return self.get(name, default_value)
f338ef
+        with self.lock:
f338ef
+            self.reload(with_lock=False)
f338ef
+            return self.get(name, default_value, with_lock=False)
f338ef
 
f338ef
     def get_help(self, name=None):
f338ef
         pass
f338ef
-- 
f338ef
1.8.3.1
f338ef