mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
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:
@@ -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.
|
||||
|
||||
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user