Commit 3dded3dc authored by Matt Joiner's avatar Matt Joiner

Do notifications synchronously

parent 98e7fc1e
......@@ -208,9 +208,6 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) {
// * The other will be decremented when Conn.start exits.
s.refs.Add(2)
// Take the notification lock before releasing the conns lock to block
// Disconnect notifications until after the Connect notifications done.
c.notifyLk.Lock()
s.conns.Unlock()
// We have a connection now. Cancel all other in-progress dials.
......@@ -220,7 +217,6 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) {
s.notifyAll(func(f inet.Notifiee) {
f.Connected(s, c)
})
c.notifyLk.Unlock()
c.start()
......@@ -438,18 +434,10 @@ func (s *Swarm) Backoff() *DialBackoff {
// notifyAll sends a signal to all Notifiees
func (s *Swarm) notifyAll(notify func(inet.Notifiee)) {
var wg sync.WaitGroup
s.notifs.RLock()
wg.Add(len(s.notifs.m))
for f := range s.notifs.m {
go func(f inet.Notifiee) {
defer wg.Done()
notify(f)
}(f)
notify(f)
}
wg.Wait()
s.notifs.RUnlock()
}
......
......@@ -65,17 +65,10 @@ func (c *Conn) doClose() {
s.Reset()
}
// do this in a goroutine to avoid deadlocking if we call close in an open notification.
go func() {
// prevents us from issuing close notifications before finishing the open notifications
c.notifyLk.Lock()
defer c.notifyLk.Unlock()
c.swarm.notifyAll(func(f inet.Notifiee) {
f.Disconnected(c.swarm, c)
})
c.swarm.refs.Done() // taken in Swarm.addConn
}()
c.swarm.notifyAll(func(f inet.Notifiee) {
f.Disconnected(c.swarm, c)
})
c.swarm.refs.Done() // taken in Swarm.addConn
}
func (c *Conn) removeStream(s *Stream) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment