Skip to content

Commit

Permalink
Fix dead lock
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 committed Nov 20, 2019
1 parent af29aab commit 71b39b7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ type EventNotify struct {
Value []byte `json:"value"`
}

func newInitEvent(rt *Runtime) (*EventNotify, error) {
func newInitEvent(snap *snap) (*EventNotify, error) {
value := goetty.NewByteBuf(512)

snap := rt.snap()
value.WriteInt(len(snap.containers))
value.WriteInt(len(snap.resources))

Expand Down Expand Up @@ -217,14 +215,15 @@ func (wn *watcherNotifier) onEvent(evt *EventNotify) {
}

func (wn *watcherNotifier) onInitWatcher(msg *InitWatcher, conn goetty.IOSession) {
log.Infof("prophet: new watcher %s added", conn.RemoteIP())
snap := wn.rt.snap()

wn.Lock()
defer wn.Unlock()

log.Infof("prophet: new watcher %s added", conn.RemoteIP())

if wn.eventC != nil {
if MatchEvent(EventInit, msg.Flag) {
nt, err := newInitEvent(wn.rt)
nt, err := newInitEvent(snap)
if err != nil {
log.Errorf("prophet: marshal init notify failed, errors:%+v", err)
conn.Close()
Expand Down

0 comments on commit 71b39b7

Please sign in to comment.