-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
There was a problem hiding this 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.
Are you sure this is what we want? In comment above direct connect we read:
So this function should not be accesses by "normal" user |
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
This PR fixes #1448