Skip to content

Commit a9c86c6

Browse files
authored
fix: duplicate watcher id (#142)
1 parent 1d58038 commit a9c86c6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/apiserver/pkg/registry/file_rest.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/alibaba/higress/api-server/pkg/utils"
3232
"github.com/fsnotify/fsnotify"
33+
"github.com/google/uuid"
3334
)
3435

3536
const fileChangeProcessInterval = 100 * time.Millisecond
@@ -78,7 +79,7 @@ func NewFileREST(
7879
newListFunc: newListFunc,
7980
attrFunc: attrFunc,
8081
dirWatcher: watcher,
81-
fileWatchers: make(map[int]*fileWatch, 10),
82+
fileWatchers: make(map[string]*fileWatch, 10),
8283
}
8384
err = f.startDirWatcher()
8485
if err != nil {
@@ -101,7 +102,7 @@ type fileREST struct {
101102
fileChangeMutex sync.Mutex
102103
fileChangeProcessTicker *time.Ticker
103104
dirWatcher *fsnotify.Watcher
104-
fileWatchers map[int]*fileWatch
105+
fileWatchers map[string]*fileWatch
105106
fileWatchersMutex sync.RWMutex
106107

107108
newFunc func() runtime.Object
@@ -643,7 +644,7 @@ func (f *fileREST) visitDir(dirname string, extension string, newFunc func() run
643644

644645
func (f *fileREST) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) {
645646
fw := &fileWatch{
646-
id: len(f.fileWatchers),
647+
id: uuid.New().String(),
647648
f: f,
648649
ch: make(chan watch.Event, 10),
649650
}
@@ -682,7 +683,7 @@ func (f *fileREST) predicateFunc(label labels.Selector, field fields.Selector) s
682683

683684
type fileWatch struct {
684685
f *fileREST
685-
id int
686+
id string
686687
ch chan watch.Event
687688
}
688689

src/apiserver/pkg/registry/nacos_rest.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/alibaba/higress/api-server/pkg/options"
1818
"github.com/alibaba/higress/api-server/pkg/utils"
19+
"github.com/google/uuid"
1920
"github.com/nacos-group/nacos-sdk-go/v2/clients/config_client"
2021
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
2122
"github.com/nacos-group/nacos-sdk-go/v2/model"
@@ -83,7 +84,7 @@ func NewNacosREST(
8384
newFunc: newFunc,
8485
newListFunc: newListFunc,
8586
attrFunc: attrFunc,
86-
watchers: make(map[int]*nacosWatch, 10),
87+
watchers: make(map[string]*nacosWatch, 10),
8788
encryptionKey: dataEncryptionKey,
8889
}
8990
n.namesDataId = n.dataIdPrefix + dataIdSeparator + namesSuffix
@@ -104,7 +105,7 @@ type nacosREST struct {
104105
listRefreshTicker *time.Ticker
105106
listConfigListened int32
106107
watchersMutex sync.RWMutex
107-
watchers map[int]*nacosWatch
108+
watchers map[string]*nacosWatch
108109

109110
newFunc func() runtime.Object
110111
newListFunc func() runtime.Object
@@ -446,7 +447,7 @@ func (n *nacosREST) Watch(ctx context.Context, options *metainternalversion.List
446447
ns, _ := genericapirequest.NamespaceFrom(ctx)
447448
predicate := n.buildListPredicate(options)
448449
nw := &nacosWatch{
449-
id: len(n.watchers),
450+
id: uuid.New().String(),
450451
f: n,
451452
ch: make(chan watch.Event, 1024),
452453
ns: ns,
@@ -738,7 +739,7 @@ func calculateMd5(str string) string {
738739

739740
type nacosWatch struct {
740741
f *nacosREST
741-
id int
742+
id string
742743
ch chan watch.Event
743744
ns string
744745
predicate *storage.SelectionPredicate

0 commit comments

Comments
 (0)