Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
847a814c
Commit
847a814c
authored
Dec 10, 2021
by
Steve Abrams
Committed by
Heinrich Lee Yu
Dec 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix registry race condition
parent
ce272f6b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
6 deletions
+40
-6
app/models/container_repository.rb
app/models/container_repository.rb
+8
-3
app/services/auth/container_registry_authentication_service.rb
...ervices/auth/container_registry_authentication_service.rb
+1
-1
spec/models/container_repository_spec.rb
spec/models/container_repository_spec.rb
+31
-2
No files found.
app/models/container_repository.rb
View file @
847a814c
...
...
@@ -145,9 +145,14 @@ class ContainerRepository < ApplicationRecord
name:
path
.
repository_name
)
end
def
self
.
create_from_path!
(
path
)
safe_find_or_create_by!
(
project:
path
.
repository_project
,
name:
path
.
repository_name
)
def
self
.
find_or_create_from_path
(
path
)
repository
=
safe_find_or_create_by
(
project:
path
.
repository_project
,
name:
path
.
repository_name
)
return
repository
if
repository
.
persisted?
find_by_path!
(
path
)
end
def
self
.
build_root_repository
(
project
)
...
...
app/services/auth/container_registry_authentication_service.rb
View file @
847a814c
...
...
@@ -156,7 +156,7 @@ module Auth
return
if
path
.
has_repository?
return
unless
actions
.
include?
(
'push'
)
ContainerRepository
.
create_from_path!
(
path
)
ContainerRepository
.
find_or_create_from_path
(
path
)
end
# Overridden in EE
...
...
spec/models/container_repository_spec.rb
View file @
847a814c
...
...
@@ -223,9 +223,9 @@ RSpec.describe ContainerRepository do
end
end
describe
'.
create_from_path!
'
do
describe
'.
find_or_create_from_path
'
do
let
(
:repository
)
do
described_class
.
create_from_path!
(
ContainerRegistry
::
Path
.
new
(
path
))
described_class
.
find_or_create_from_path
(
ContainerRegistry
::
Path
.
new
(
path
))
end
let
(
:repository_path
)
{
ContainerRegistry
::
Path
.
new
(
path
)
}
...
...
@@ -291,6 +291,35 @@ RSpec.describe ContainerRepository do
expect
(
repository
.
id
).
to
eq
(
container_repository
.
id
)
end
end
context
'when many of the same repository are created at the same time'
do
let
(
:path
)
{
ContainerRegistry
::
Path
.
new
(
project
.
full_path
+
'/some/image'
)
}
it
'does not throw validation errors and only creates one repository'
do
expect
{
repository_creation_race
(
path
)
}.
to
change
{
ContainerRepository
.
count
}.
by
(
1
)
end
it
'retrieves a persisted repository for all concurrent calls'
do
repositories
=
repository_creation_race
(
path
).
map
(
&
:value
)
expect
(
repositories
).
to
all
(
be_persisted
)
end
end
def
repository_creation_race
(
path
)
# create a race condition - structure from https://blog.arkency.com/2015/09/testing-race-conditions/
wait_for_it
=
true
threads
=
Array
.
new
(
10
)
do
|
i
|
Thread
.
new
do
true
while
wait_for_it
::
ContainerRepository
.
find_or_create_from_path
(
path
)
end
end
wait_for_it
=
false
threads
.
each
(
&
:join
)
end
end
describe
'.build_root_repository'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment