Improve import_ctf reliability (#1419)

* Improve `import_ctf()` reliability by closing all connections before dropping & recreating database
* Close database session in IP tracking code in failure situations
This commit is contained in:
Kevin Chung
2020-05-18 11:46:15 -04:00
committed by GitHub
parent ac24b83a86
commit 148bdccf26
2 changed files with 6 additions and 0 deletions

View File

@@ -123,6 +123,11 @@ def import_ctf(backup, erase=True):
)
if erase:
# Clear out existing connections to release any locks
db.session.close()
db.engine.dispose()
# Drop database and recreate it to get to a clean state
drop_database()
create_database()
# We explicitly do not want to upgrade or stamp here.

View File

@@ -201,6 +201,7 @@ def init_request_processors(app):
db.session.commit()
except (InvalidRequestError, IntegrityError):
db.session.rollback()
db.session.close()
logout_user()
else:
clear_user_recent_ips(user_id=session["id"])