プロジェクト

全般

プロフィール

Vote #81199

完了

Fix possible race condition with parallel, identical file uploads

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Attachments_19
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
19
version_id:
162
issue_org_id:
34479
author_id:
40856
assigned_to_id:
332
comments:
6
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

There is a race condition with multiple application processes when uploading multiple identical files at the same time, which may lead to attachments pointing to files that do not exist, if attachment creation and deduplication are executed in a particular order:

  • Attachment A0 exists in the system.
  • identical Attachment A1 is created in one process
  • identical Attachment A2 is created at the same time in another application process
  • for some reason, A2 is deduplicated before A1 and now points to A1's diskfile
  • A1 is deduplicated and now points to A0's diskfile

Since during deduplication of A1, A1's original disk file is deleted, A2 now points to a non existent file.
To fix that, an additional check whether the file really is not referenced anymore before deleting it is introduced.

In plain Redmine usage scenarios this is really a very unlikely scenario, but we had it happen with our WebDAV integration where whole directory trees can be uploaded at once. Should the issue indeed have manifested itself somewhere else, it can easily be fixed by finding unreadable attachment records, using the digest to find an identical, readable attachment and correcting the disk location accordingly:

unreadables = Attachment.all.reject(&:readable?)
unreadables.each do |u|
  if readable = Attachment.where(filesize: u.filesize, digest: u.digest).detect(&:readable?)
    u.update_columns disk_directory: readable.disk_directory, disk_filename: readable.disk_filename
  end
end


journals

--------------------------------------------------------------------------------
We had a situation, when several files with the same name were uploaded at the same time. All they got the same disk filename.
As a result different container objects now point to the same file, which should actually belong to only one of them. Other files got lost (overridden).
--------------------------------------------------------------------------------
Setting the target version to 4.1.2.
--------------------------------------------------------------------------------
All tests pass with the patch applied on the current trunk: https://gitlab.com/redmine-org/redmine/-/pipelines/270891057
--------------------------------------------------------------------------------
Committed the patch. Thank you.
--------------------------------------------------------------------------------
Andriy Lesyuk wrote:
> We had a situation, when several files with the same name were uploaded at the same time. All they got the same disk filename.
> As a result different container objects now point to the same file, which should actually belong to only one of them. Other files got lost (overridden).

see #35539 for a patch fixing this.
--------------------------------------------------------------------------------

Admin Redmine さんが3年以上前に更新

  • カテゴリAttachments_19 にセット
  • 対象バージョン4.1.2_162 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0