prevent premature peer gc

Caused by a race between adding the connection to our map and
receiving a topology gossip on it.

We remove the race by making AddConnection synchronous and invoking it
prior to entering the tcp receive loop.

Fixes #367.
This commit is contained in:
Matthias Radestock committed 2015-01-31 22:29:07 +00:00
1 parent 5892cae5d0
commit 2d135f3da0
2 files changed
+26 -6

No files matched your search

+5 -3
View File
@@ -123,12 +123,13 @@ const (
PSendProtocolMsg
)
// Async: rely on the peer to shut us down if we shouldn't be adding
// ourselves, so therefore this can be async
// Sync.
func (peer *LocalPeer) AddConnection(conn *LocalConnection) {
resultChan := make(chan interface{})
peer.queryChan <- &PeerInteraction{
Interaction: Interaction{code: PAddConnection},
Interaction: Interaction{code: PAddConnection, resultChan: resultChan},
payload: conn}
<-resultChan
}
// Async.
@@ -170,6 +171,7 @@ func (peer *LocalPeer) queryLoop(queryChan <-chan *PeerInteraction) {
if peer.handleAddConnection(conn) {
conn.log("connection added")
}
query.resultChan <- nil
case PConnectionEstablished:
conn := query.payload.(*LocalConnection)
if peer.handleConnectionEstablished(conn) {