This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4561 - domcleal:4519-concurrent-ci-updater, r=indirect
Safely store concurrent compact index downloads When bundler is run concurrently using the same bundle dir in $HOME, the versions file can be updated from two processes at once. The download has been changed to a temporary file, which is securely moved into place over the original. If retrying the update operation, the original file is no longer immediately deleted and instead a full download is performed, later overwriting the original file if successful. If two processes are updating in parallel, this should ensure the original file isn't corrupted and that both processes succeed. - Fixes #4519 --- This would be useful on 1.12.x if possible, since the new caching behaviour with a shared home directory is causing the errors described in #4519.
- Loading branch information
Showing
4 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
spec/support/artifice/compact_index_concurrent_download.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path("../compact_index", __FILE__) | ||
|
||
Artifice.deactivate | ||
|
||
class CompactIndexConcurrentDownload < CompactIndexAPI | ||
get "/versions" do | ||
versions = File.join(Bundler.rubygems.user_home, ".bundle", "cache", "compact_index", | ||
"localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "versions") | ||
|
||
# Verify the original (empty) content hasn't been deleted, e.g. on a retry | ||
File.read(versions) == "" || raise("Original file should be present and empty") | ||
|
||
# Verify this is only requested once for a partial download | ||
env["HTTP_RANGE"] || raise("Missing Range header for expected partial download") | ||
|
||
# Overwrite the file in parallel, which should be then overwritten | ||
# after a successful download to prevent corruption | ||
File.open(versions, "w") {|f| f.puts "another process" } | ||
|
||
etag_response do | ||
file = tmp("versions.list") | ||
file.delete if file.file? | ||
file = CompactIndex::VersionsFile.new(file.to_s) | ||
file.update_with(gems) | ||
CompactIndex.versions(file, nil, {}) | ||
end | ||
end | ||
end | ||
|
||
Artifice.activate_with(CompactIndexConcurrentDownload) |