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 race condition and nil pointer dereference in holepunch #1467

Closed
wants to merge 2 commits into from
Closed

fix race condition and nil pointer dereference in holepunch #1467

wants to merge 2 commits into from

Conversation

watjurk
Copy link
Contributor

@watjurk watjurk commented Apr 27, 2022

This PR fixes #1448

Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

There's another use of the holePuncher in DirectConnect. This should also be protected by the mutex.

@watjurk
Copy link
Contributor Author

watjurk commented Apr 28, 2022

Are you sure this is what we want? In comment above direct connect we read:

// DirectConnect is only exposed for testing purposes.
// TODO: find a solution for this.

So this function should not be accesses by "normal" user

@marten-seemann
Copy link
Contributor

True, but doesn’t cost us anything to lock the mutex there as well, so let’s do it.

@@ -257,5 +266,7 @@ func (s *Service) handleNewStream(str network.Stream) {
// TODO: find a solution for this.
func (s *Service) DirectConnect(p peer.ID) error {
<-s.hasPublicAddrsChan
s.holePuncherMx.Lock()
defer s.holePuncherMx.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

This locks the mutex for a very long time (on the order of 10s or so). Save s.holePuncher to a local variable instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or maybe just use RMutex? And call RLock?

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.

holepunch: s.holePuncher is nil on close
2 participants