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