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
0cdd2aba
Commit
0cdd2aba
authored
Dec 22, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18956 from wojtek-t/debug_etcd_generic
Fix race in EtcdWatcher
parents
4b18fa55
62972321
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
14 deletions
+33
-14
etcd_watcher.go
pkg/storage/etcd/etcd_watcher.go
+33
-14
No files found.
pkg/storage/etcd/etcd_watcher.go
View file @
0cdd2aba
...
...
@@ -144,23 +144,42 @@ func (w *etcdWatcher) etcdWatch(ctx context.Context, client etcd.KeysAPI, key st
defer
util
.
HandleCrash
()
defer
close
(
w
.
etcdError
)
defer
close
(
w
.
etcdIncoming
)
if
resourceVersion
==
0
{
latest
,
err
:=
etcdGetInitialWatchState
(
ctx
,
client
,
key
,
w
.
list
,
w
.
etcdIncoming
)
if
err
!=
nil
{
w
.
etcdError
<-
err
return
// We need to be prepared, that Stop() can be called at any time.
// It can potentially also be called, even before this function is called.
// If that is the case, we simply skip all the code here.
// See #18928 for more details.
var
watcher
etcd
.
Watcher
returned
:=
func
()
bool
{
w
.
stopLock
.
Lock
()
defer
w
.
stopLock
.
Unlock
()
if
w
.
stopped
{
// Watcher has already been stopped - don't event initiate it here.
return
true
}
// Perform initialization of watcher under lock - we want to avoid situation when
// Stop() is called in the meantime (which in tests can cause etcd termination and
// strange behavior here).
if
resourceVersion
==
0
{
latest
,
err
:=
etcdGetInitialWatchState
(
ctx
,
client
,
key
,
w
.
list
,
w
.
etcdIncoming
)
if
err
!=
nil
{
w
.
etcdError
<-
err
return
true
}
resourceVersion
=
latest
}
resourceVersion
=
latest
}
opts
:=
etcd
.
WatcherOptions
{
Recursive
:
w
.
list
,
AfterIndex
:
resourceVersion
,
opts
:=
etcd
.
WatcherOptions
{
Recursive
:
w
.
list
,
AfterIndex
:
resourceVersion
,
}
watcher
=
client
.
Watcher
(
key
,
&
opts
)
w
.
ctx
,
w
.
cancel
=
context
.
WithCancel
(
ctx
)
return
false
}()
if
returned
{
return
}
watcher
:=
client
.
Watcher
(
key
,
&
opts
)
w
.
stopLock
.
Lock
()
w
.
ctx
,
w
.
cancel
=
context
.
WithCancel
(
ctx
)
w
.
stopLock
.
Unlock
()
for
{
resp
,
err
:=
watcher
.
Next
(
w
.
ctx
)
...
...
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