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

Not able to perform List.Members() inside a NotifyJoin()/NotifyLeave() as it results in deadlock #237

Open
sandyydk opened this issue May 18, 2021 · 2 comments

Comments

@sandyydk
Copy link

Not able to perform List.Members() inside a NotifyJoin()/NotifyLeave() as it results in deadlock. I see a single lock being used for the both.
is there a way to find total nodes in the cluster when an event occurs?

@sandyydk
Copy link
Author

func (m *Memberlist) Members() []*Node {
	m.nodeLock.RLock()
	defer m.nodeLock.RUnlock()
func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
	m.nodeLock.Lock()
	defer m.nodeLock.Unlock()

Both end up trying to acquire the same lock.

@ozon2
Copy link

ozon2 commented Jul 2, 2021

I had the same issue. I ended up using a channel to avoid using list.Members() inside NotifyJoin().

type eventDelegate struct {
    eventChan chan memberlist.NodeEventType
}

func (ed *eventDelegate) NotifyJoin(node *memberlist.Node) {
    ed.eventChan <- memberlist.NodeJoin
}
for {
    event := <-eventChan
    members := list.Members()
}

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

No branches or pull requests

2 participants