Skip to content

Commit

Permalink
fix: Hang in watch when resouce list count is greater than channel le…
Browse files Browse the repository at this point in the history
…ngth (higress-group#115)

* fix: Hang in watch when resouce list count is greater than channel length

* Update nacos_rest.go

---------

Co-authored-by: Kent Dong <[email protected]>
  • Loading branch information
lhlxc and CH3CHO authored Dec 21, 2024
1 parent f8cf408 commit 316b611
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/apiserver/pkg/registry/file_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,17 @@ func (f *fileREST) Watch(ctx context.Context, options *metainternalversion.ListO
return nil, err
}

danger := reflect.ValueOf(list).Elem()
items := danger.FieldByName("Items")
go func() {
danger := reflect.ValueOf(list).Elem()
items := danger.FieldByName("Items")

for i := 0; i < items.Len(); i++ {
fw.ch <- watch.Event{
Type: watch.Added,
Object: listItemToRuntimeObject(items.Index(i)),
for i := 0; i < items.Len(); i++ {
fw.ch <- watch.Event{
Type: watch.Added,
Object: listItemToRuntimeObject(items.Index(i)),
}
}
}
}()

f.fileWatchersMutex.Lock()
f.fileWatchers[fw.id] = fw
Expand Down
20 changes: 11 additions & 9 deletions src/apiserver/pkg/registry/nacos_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,17 @@ func (n *nacosREST) Watch(ctx context.Context, options *metainternalversion.List
return nil, err
}

danger := reflect.ValueOf(list).Elem()
items := danger.FieldByName("Items")

for i := 0; i < items.Len(); i++ {
nw.SendEvent(watch.Event{
Type: watch.Added,
Object: listItemToRuntimeObject(items.Index(i)),
}, true)
}
go func() {
danger := reflect.ValueOf(list).Elem()
items := danger.FieldByName("Items")

for i := 0; i < items.Len(); i++ {
nw.SendEvent(watch.Event{
Type: watch.Added,
Object: listItemToRuntimeObject(items.Index(i)),
}, true)
}
}()

n.watchersMutex.Lock()
defer n.watchersMutex.Unlock()
Expand Down

0 comments on commit 316b611

Please sign in to comment.