Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a246d6f1
Commit
a246d6f1
authored
Nov 06, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apiserver: protect registry cleanup against concurrent access
parent
21062657
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
+18
-5
storage_factory.go
...piserver/pkg/registry/generic/registry/storage_factory.go
+18
-5
No files found.
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/storage_factory.go
View file @
a246d6f1
...
@@ -17,6 +17,8 @@ limitations under the License.
...
@@ -17,6 +17,8 @@ limitations under the License.
package
registry
package
registry
import
(
import
(
"sync"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
...
@@ -82,13 +84,23 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
...
@@ -82,13 +84,23 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
// only from the test harness, so Register/Cleanup will be
// only from the test harness, so Register/Cleanup will be
// no-op at runtime.
// no-op at runtime.
var
cleanupLock
sync
.
Mutex
var
cleanup
[]
func
()
=
nil
var
cleanup
[]
func
()
=
nil
func
TrackStorageCleanup
()
{
func
TrackStorageCleanup
()
{
cleanupLock
.
Lock
()
defer
cleanupLock
.
Unlock
()
if
cleanup
!=
nil
{
panic
(
"Conflicting storage tracking"
)
}
cleanup
=
make
([]
func
(),
0
)
cleanup
=
make
([]
func
(),
0
)
}
}
func
RegisterStorageCleanup
(
fn
func
())
{
func
RegisterStorageCleanup
(
fn
func
())
{
cleanupLock
.
Lock
()
defer
cleanupLock
.
Unlock
()
if
cleanup
==
nil
{
if
cleanup
==
nil
{
return
return
}
}
...
@@ -96,11 +108,12 @@ func RegisterStorageCleanup(fn func()) {
...
@@ -96,11 +108,12 @@ func RegisterStorageCleanup(fn func()) {
}
}
func
CleanupStorage
()
{
func
CleanupStorage
()
{
if
cleanup
==
nil
{
cleanupLock
.
Lock
()
return
old
:=
cleanup
}
cleanup
=
nil
for
_
,
d
:=
range
cleanup
{
cleanupLock
.
Unlock
()
for
_
,
d
:=
range
old
{
d
()
d
()
}
}
cleanup
=
nil
}
}
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