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

cover.Store.GetAll() return a map will potentially cause panic(a map without protection) #137

Closed
gavwu opened this issue Dec 7, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@gavwu
Copy link
Contributor

gavwu commented Dec 7, 2020

// memoryStore holds the registered services only into memory
type memoryStore struct {
	mu          sync.RWMutex
	servicesMap map[string][]string
}

// Get returns all the registered service information
func (l *memoryStore) GetAll() map[string][]string {
	l.mu.RLock()
	defer l.mu.RUnlock()
	return l.servicesMap
}

Proposal:

  1. Clone a map and return
  2. Support access the map under protection
@CarlJi CarlJi added the enhancement New feature or request label Dec 8, 2020
@CarlJi
Copy link
Collaborator

CarlJi commented Dec 8, 2020

Great suggestion 👍

@gavwu
Copy link
Contributor Author

gavwu commented Dec 10, 2020

To preserve the meaning of GetAll, I prefer to clone a map and return it, potentially leave the overhead to the caller (caller should know this function call will be expensive)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants