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/service discovery #96

Merged
merged 5 commits into from
Mar 21, 2019
Merged

Fix/service discovery #96

merged 5 commits into from
Mar 21, 2019

Conversation

andrehp
Copy link
Contributor

@andrehp andrehp commented Mar 19, 2019

Fixes #95

@coveralls
Copy link

coveralls commented Mar 20, 2019

Pull Request Test Coverage Report for Build 811

  • 45 of 45 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 68.781%

Files with Coverage Reduction New Missed Lines %
cluster/etcd_service_discovery.go 2 79.77%
Totals Coverage Status
Change from base Build 802: 0.2%
Covered Lines: 4327
Relevant Lines: 6291

💛 - Coveralls

if svMap, ok := sd.serverMapByType.Load(sv.Type); ok {
sm := svMap.(map[string]*Server)
delete(sm, sv.ID)
sd.mapByTypeLock.Lock()
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

cluster/etcd_service_discovery.go Outdated Show resolved Hide resolved
cluster/etcd_service_discovery.go Outdated Show resolved Hide resolved
cluster/etcd_service_discovery.go Show resolved Hide resolved
cluster/etcd_service_discovery.go Outdated Show resolved Hide resolved
@cscatolini
Copy link
Contributor

Great job 😍

@cscatolini cscatolini merged commit 76aee35 into master Mar 21, 2019
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.

4 participants