get rid of GossipSender gc
With the per-broadcast-source GossipSenders gone, we can get rid of GossipSender gc... Instead of maintaining a Connection->GossipSender map in the GossipChannels - which we then need to gc when connections get closed - we keep gossip_channel_name->GossipSender maps in LocalConnections. Access to the map is guarded by a separate lock, rather than re-using the LocalConnection lock. This reduces lock contention and risk of deadlock. In the GossipSenders, we replace the Stop() method with a signalling channel, i.e. senders stop when that channel gets closed. Handily, the LocalConnection.finished channel fits that description. So when a LocalConnection's run loop terminates, any existing and future associated GossipSenders will end up terminating too.
This commit is contained in:
1 parent
bbd0b15792
commit
969dc4e527
4 files changed
+61
-53
No files matched your search
@@ -53,6 +53,11 @@ type LocalConnection struct {
|
||||
errorChan chan<- error
|
||||
finished <-chan struct{} // closed to signal that actorLoop has finished
|
||||
OverlayConn OverlayConnection
|
||||
gossipSenders *GossipSenders
|
||||
}
|
||||
|
||||
type GossipConnection interface {
|
||||
GossipSenders() *GossipSenders
|
||||
}
|
||||
|
||||
type ConnectionAction func() error
|
||||
@@ -101,6 +106,7 @@ func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, ro
|
||||
actionChan: actionChan,
|
||||
errorChan: errorChan,
|
||||
finished: finished}
|
||||
conn.gossipSenders = NewGossipSenders(conn, finished)
|
||||
go conn.run(actionChan, errorChan, finished, acceptNewPeer)
|
||||
}
|
||||
|
||||
@@ -129,6 +135,10 @@ func (conn *LocalConnection) SendProtocolMsg(m ProtocolMsg) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (conn *LocalConnection) GossipSenders() *GossipSenders {
|
||||
return conn.gossipSenders
|
||||
}
|
||||
|
||||
// ACTOR methods
|
||||
|
||||
// NB: The conn.* fields are only written by the connection actor
|
||||
|
||||
Reference in new issue
Block a user