-
Notifications
You must be signed in to change notification settings - Fork 481
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/service discovery #96
Conversation
Pull Request Test Coverage Report for Build 811
💛 - Coveralls |
cluster/etcd_service_discovery.go
Outdated
if svMap, ok := sd.serverMapByType.Load(sv.Type); ok { | ||
sm := svMap.(map[string]*Server) | ||
delete(sm, sv.ID) | ||
sd.mapByTypeLock.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to defer sd.mapByTypeLock.Unlock()
right after locking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that there is only one flow deferring is slower and would be executed only after notifying the listeners
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a point, but if we panic in the next lines there's a chance we won't release the lock. Maybe wrap what really needs to be inside the lock in another method and call it from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scope of a defer is its function, it would get really ugly to create a function just to wrap the lock and deal with panics. A panic here would lead to the crash of the application, which seems the proper behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I created a wrapper for the lock, what do you think?
Great job 😍 |
Fixes #95