Skip to content

Implement Close and fix reaper goroutine leak. #95

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

Merged
merged 3 commits into from
May 1, 2015

Conversation

vmihailenco
Copy link
Collaborator

@dim please review

Also do you any plans how to release v3 with latest API changes and Cluster client?

@vmihailenco vmihailenco force-pushed the fix/close-client-and-reaper branch from a6b205f to d00fb6e Compare May 1, 2015 06:38
@dim
Copy link
Contributor

dim commented May 1, 2015

You are not unlocking clientMx when c.closed on two occasions. Sometimes it's worth accepting the additional allocation and simply deferring the Unlock to improve code readability, I think

@dim
Copy link
Contributor

dim commented May 1, 2015

I also think you should cache the ticker on the client instance and close(c.ticker.C) when closing the client to make sure the reaper goroutine doesn't linger around unnecessarily.

@vmihailenco
Copy link
Collaborator Author

@dim thanks, fixed. PTAL.

@vmihailenco
Copy link
Collaborator Author

PTAL

func (c *ClusterClient) Close() error {
// TODO: close should make client unusable
c.setSlots(nil)
defer c.clientsMx.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a problem, just out of interest: what's the benefit of deferring the unlock before acquiring the lock? I've seen you doing it on a few occasions. Looks like no one else is doing it this way 'round.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should be slightly faster (I believe), because defer c.clientsMx.Unlock() is evaluated before the lock is acquired. It does not matter too much and I have to stop doing this.

@dim
Copy link
Contributor

dim commented May 1, 2015

Cool, ship it! :)

vmihailenco added a commit that referenced this pull request May 1, 2015
Implement Close and fix reaper goroutine leak.
@vmihailenco vmihailenco merged commit f7a1636 into master May 1, 2015
@vmihailenco vmihailenco deleted the fix/close-client-and-reaper branch May 1, 2015 11:20
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