[LNT] r312741 - async_ops: Do not dispose pre-fork DB connections

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 12:25:32 PDT 2017


Author: matze
Date: Thu Sep  7 12:25:32 2017
New Revision: 312741

URL: http://llvm.org/viewvc/llvm-project?rev=312741&view=rev
Log:
async_ops: Do not dispose pre-fork DB connections

It turns out that the hack in async_ops that disposes the DB connections
present before forking the new process is actively harmful (at least for
postgres/psycopg2 setups) and appears to disrupt the connections of the
original process. The recent session cleanup seems to have made this
hack obsolete so remove it.

Modified:
    lnt/trunk/lnt/server/db/v4db.py
    lnt/trunk/lnt/util/async_ops.py

Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=312741&r1=312740&r2=312741&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Thu Sep  7 12:25:32 2017
@@ -24,8 +24,6 @@ class V4DB(object):
     """
     Wrapper object for LNT v0.4+ databases.
     """
-    _engine_lock = threading.Lock()
-    _engines = []
     def _load_schema_file(self, schema_file):
         session = self.make_session()
         with open(schema_file) as schema_fd:
@@ -72,8 +70,6 @@ class V4DB(object):
             connect_args['timeout'] = 30
         self.engine = sqlalchemy.create_engine(path,
                                                connect_args=connect_args)
-        with V4DB._engine_lock:
-            V4DB._engines.append(self.engine)
 
         # Update the database to the current version, if necessary. Only check
         # this once per path.
@@ -87,14 +83,6 @@ class V4DB(object):
     def close(self):
         self.engine.dispose()
 
-    @staticmethod
-    def close_all_engines():
-        """Hack for async_ops. Do not use for anything else."""
-        with V4DB._engine_lock:
-            for engine in V4DB._engines:
-                engine.dispose()
-            V4DB._engines = []
-
     def make_session(self):
         return self.sessionmaker()
 

Modified: lnt/trunk/lnt/util/async_ops.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/async_ops.py?rev=312741&r1=312740&r2=312741&view=diff
==============================================================================
--- lnt/trunk/lnt/util/async_ops.py (original)
+++ lnt/trunk/lnt/util/async_ops.py Thu Sep  7 12:25:32 2017
@@ -113,25 +113,15 @@ def async_run_job(job, db_name, ts, func
     JOBS.append(job)
 
 
-# Flag to track if we have disposed of the parents database connections in
-# this subprocess.
-clean_db = False
-
-
 def async_wrapper(job, ts_args, func_args):
     """Setup test-suite in this subprocess and run something.
 
     Because of multipocessing, capture excptions and log messages,
     and return them.
     """
-    global clean_db
     try:
         start_time = time.time()
 
-        if not clean_db:
-            lnt.server.db.v4db.V4DB.close_all_engines()
-            clean_db = True
-
         sleep(3)
         logger.info("Running async wrapper: {} ".format(job.__name__) +
                     str(os.getpid()))
@@ -139,10 +129,10 @@ def async_wrapper(job, ts_args, func_arg
         db = config.get_database(ts_args['db'])
         with contextlib.closing(db):
             session = db.make_session()
-            ts = db.testsuite[ts_args['tsname']]
-            nothing = job(session, ts, **func_args)
-            assert nothing is None
-            session.close()
+            with contextlib.closing(session):
+                ts = db.testsuite[ts_args['tsname']]
+                nothing = job(session, ts, **func_args)
+                assert nothing is None
         end_time = time.time()
         delta = end_time-start_time
         msg = "Finished: {name} in {time:.2f}s ".format(name=job.__name__,




More information about the llvm-commits mailing list