diff options
author | Rémy Coutable <remy@rymai.me> | 2019-01-15 10:39:48 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-01-15 10:39:48 +0000 |
commit | 11d6c7e2f852536c9a05fe3fdf7e82be7d38f96e (patch) | |
tree | 9e3d5aa2c205d21e1438664bd76df9372e67c100 /app | |
parent | 6357ff1104c7bb11b0bd434e38b2b270e08aa354 (diff) | |
parent | bcdb5a0a2d62caa685c32c5d1a4453bd5926b5b1 (diff) | |
download | gitlab-ce-11d6c7e2f852536c9a05fe3fdf7e82be7d38f96e.tar.gz |
Merge branch 'sh-fix-issue-55161' into 'master'
Fix failing MySQL spec due to deadlock condition
Closes #55161
See merge request gitlab-org/gitlab-ce!24378
Diffstat (limited to 'app')
-rw-r--r-- | app/uploaders/records_uploads.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/app/uploaders/records_uploads.rb b/app/uploaders/records_uploads.rb index 0efca895a50..9a243e07936 100644 --- a/app/uploaders/records_uploads.rb +++ b/app/uploaders/records_uploads.rb @@ -23,13 +23,23 @@ module RecordsUploads return unless model return unless file && file.exists? - Upload.transaction do - uploads.where(path: upload_path).delete_all - upload.delete if upload - - self.upload = build_upload.tap(&:save!) + # MySQL InnoDB may encounter a deadlock if a deletion and an + # insert is in the same transaction due to its next-key locking + # algorithm, so we need to skip the transaction. + # https://gitlab.com/gitlab-org/gitlab-ce/issues/55161#note_131556351 + if Gitlab::Database.mysql? + readd_upload + else + Upload.transaction { readd_upload } end end + + def readd_upload + uploads.where(path: upload_path).delete_all + upload.delete if upload + + self.upload = build_upload.tap(&:save!) + end # rubocop: enable CodeReuse/ActiveRecord def upload_path |