Skip to content

Commit 11d6c7e

Browse files
committed
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
2 parents 6357ff1 + bcdb5a0 commit 11d6c7e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

app/uploaders/records_uploads.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@ def record_upload(_tempfile = nil)
2323
return unless model
2424
return unless file && file.exists?
2525

26-
Upload.transaction do
27-
uploads.where(path: upload_path).delete_all
28-
upload.delete if upload
29-
30-
self.upload = build_upload.tap(&:save!)
26+
# MySQL InnoDB may encounter a deadlock if a deletion and an
27+
# insert is in the same transaction due to its next-key locking
28+
# algorithm, so we need to skip the transaction.
29+
# https://gitlab.com/gitlab-org/gitlab-ce/issues/55161#note_131556351
30+
if Gitlab::Database.mysql?
31+
readd_upload
32+
else
33+
Upload.transaction { readd_upload }
3134
end
3235
end
36+
37+
def readd_upload
38+
uploads.where(path: upload_path).delete_all
39+
upload.delete if upload
40+
41+
self.upload = build_upload.tap(&:save!)
42+
end
3343
# rubocop: enable CodeReuse/ActiveRecord
3444

3545
def upload_path

0 commit comments

Comments
 (0)