From 2e3f7d221e1f8e88a5ea574f4cb6d8367b984768 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 03 2017 08:30:22 +0000 Subject: Retry 3 times to log the action in the DB before bailing. This fixes an error that occurred recently on pagure over dist-git where suddenly we ran into a ``(TransactionRollbackError) deadlock detected`` error. When this occurs, we will try to wait a little bit and come back to try logging the action, two times (meaning we tried three times to log the action). After this, we'll just bail and raise the error. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 36a3d28..978630b 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -26,6 +26,7 @@ import fnmatch import hashlib import logging import os +import time import tempfile import subprocess import urlparse @@ -42,6 +43,7 @@ import sqlalchemy import sqlalchemy.schema from sqlalchemy import func from sqlalchemy import asc +from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.orm import aliased from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import scoped_session @@ -4079,7 +4081,7 @@ def get_user_activity_day(session, user, date): return query.all() -def log_action(session, action, obj, user_obj): +def log_action(session, action, obj, user_obj, cnt=0): ''' Log an user action on a project/issue/PR. ''' project_id = None if obj.isa in ['issue', 'pull-request']: @@ -4103,7 +4105,14 @@ def log_action(session, action, obj, user_obj): setattr(log, 'pull_request_uid', obj.uid) session.add(log) - session.commit() + try: + session.commit() + except SQLAlchemyError: + time.sleep(1) + if cnt < 2: + return log_action(session, action, obj, user_obj, cnt=cnt+1) + else: + raise def email_logs_count(session, email):