Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate watcher id #142

Merged
merged 1 commit into from
Mar 13, 2025
Merged

fix: duplicate watcher id #142

merged 1 commit into from
Mar 13, 2025

Conversation

lhlxc
Copy link
Contributor

@lhlxc lhlxc commented Mar 13, 2025

Use watcher list length as watcher id could lead to duplicate watcher id, then the exist watcher will lost. This could happen when some watcher stopped and new watcher create.

  1. create two watcher.
    id: 0
    id: 1

  2. watcher with id 0 stopped,watcher list length is 1 now.

func (w *fileWatch) Stop() {
w.f.fileWatchersMutex.Lock()
delete(w.f.fileWatchers, w.id)
w.f.fileWatchersMutex.Unlock()
}

  1. create new watcher, it's id is the watcher list length 1, which is duplicate with existing watcher.

func (f *fileREST) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error) {
fw := &fileWatch{
id: len(f.fileWatchers),
f: f,
ch: make(chan watch.Event, 10),
}

@lhlxc lhlxc requested review from johnlanni and CH3CHO as code owners March 13, 2025 07:11
Copy link
Collaborator

@CH3CHO CH3CHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Thanks.

@CH3CHO CH3CHO merged commit a9c86c6 into higress-group:main Mar 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants