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

trying to access a nil pointer at PeersState.lastConnectedAndDiscovered #2266

Closed
EclesioMeloJunior opened this issue Feb 3, 2022 · 0 comments · Fixed by #2267
Closed

trying to access a nil pointer at PeersState.lastConnectedAndDiscovered #2266

EclesioMeloJunior opened this issue Feb 3, 2022 · 0 comments · Fixed by #2267
Assignees

Comments

@EclesioMeloJunior
Copy link
Member

Describe the bug

Inside the ./dot/peerstate/peerstate.go file the method lastConnectedAndDiscovered calls the method getNode with the current condition:

node, err := ps.getNode(peerID)
if err != nil && node.state[set] == notConnected {
    return node.lastConnected[set]
}

However, this condition is not correct because ps.getNode returns nil, ErrPeerDoesNotExist if the peerID is not in the map, so the expression node.state[... will cause a nil pointer panic

Possible Solution

Return the error

node, err := ps.getNode(peerID)
if err != nil {
   return time.Time{}, err
}

if node.state[set] == notConnected {
    return node.lastConnected[set], nil
}

return time.Now(), nil
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 a pull request may close this issue.

2 participants