[repository] fix so that when repository is shutting down, internal session in transaction are interrupted stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 06 Jul 2010 17:09:14 +0200
branchstable
changeset 5906 d40ced753291
parent 5903 aa01eb033620
child 5920 6c0a7a881024
child 5925 a1a334d93439
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
pytestconf.py
server/repository.py
server/session.py
--- a/pytestconf.py	Tue Jul 06 13:54:57 2010 +0200
+++ b/pytestconf.py	Tue Jul 06 17:09:14 2010 +0200
@@ -40,7 +40,7 @@
 
 def clean_repo_test_cls(cls):
     if 'repo' in cls.__dict__:
-        if not cls.repo._shutting_down:
+        if not cls.repo.shutting_down:
             cls.repo.shutdown()
         del cls.repo
     for clsattr in ('cnx', '_orig_cnx', 'config', '_config', 'vreg', 'schema'):
--- a/server/repository.py	Tue Jul 06 13:54:57 2010 +0200
+++ b/server/repository.py	Tue Jul 06 17:09:14 2010 +0200
@@ -125,6 +125,8 @@
         # sources
         self.sources = []
         self.sources_by_uri = {}
+        # shutdown flag
+        self.shutting_down = False
         # FIXME: store additional sources info in the system database ?
         # FIXME: sources should be ordered (add_entity priority)
         for uri, source_config in config.sources().items():
@@ -215,7 +217,6 @@
         for i in xrange(config['connections-pool-size']):
             self.pools.append(pool.ConnectionsPool(self.sources))
             self._available_pools.put_nowait(self.pools[-1])
-        self._shutting_down = False
         if config.quick_start:
             config.init_cubes(self.get_cubes())
         self.hm = hook.HooksManager(self.vreg)
@@ -323,8 +324,8 @@
         """called on server stop event to properly close opened sessions and
         connections
         """
-        assert not self._shutting_down, 'already shutting down'
-        self._shutting_down = True
+        assert not self.shutting_down, 'already shutting down'
+        self.shutting_down = True
         self.system_source.shutdown()
         if isinstance(self._looping_tasks, tuple): # if tasks have been started
             for looptask in self._looping_tasks:
@@ -800,7 +801,7 @@
     def _get_session(self, sessionid, setpool=False, txid=None,
                      checkshuttingdown=True):
         """return the user associated to the given session identifier"""
-        if checkshuttingdown and self._shutting_down:
+        if checkshuttingdown and self.shutting_down:
             raise Exception('Repository is shutting down')
         try:
             session = self._sessions[sessionid]
--- a/server/session.py	Tue Jul 06 13:54:57 2010 +0200
+++ b/server/session.py	Tue Jul 06 17:09:14 2010 +0200
@@ -1031,6 +1031,14 @@
         self.cnxtype = 'inmemory'
         self.disable_hook_categories('integrity')
 
+    @property
+    def pool(self):
+        """connections pool, set according to transaction mode for each query"""
+        if self.repo.shutting_down:
+            self.reset_pool(True)
+            raise Exception('repository is shutting down')
+        return getattr(self._threaddata, 'pool', None)
+
 
 class InternalManager(object):
     """a manager user with all access rights used internally for task such as