fix data race in ownership of RPC when piggybacking control messages.
This commit is contained in:
parent
02d5c50ff0
commit
de4adefafb
16
comm.go
16
comm.go
@ -122,3 +122,19 @@ func rpcWithControl(msgs []*pb.Message,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func copyRPC(rpc *RPC) *RPC {
|
||||
return &RPC{
|
||||
RPC: pb.RPC{
|
||||
Subscriptions: rpc.Subscriptions,
|
||||
Publish: rpc.Publish,
|
||||
Control: &pb.ControlMessage{
|
||||
Ihave: rpc.Control.Ihave,
|
||||
Iwant: rpc.Control.Iwant,
|
||||
Graft: rpc.Control.Graft,
|
||||
Prune: rpc.Control.Prune,
|
||||
},
|
||||
},
|
||||
from: rpc.from,
|
||||
}
|
||||
}
|
||||
|
@ -308,9 +308,14 @@ func (gs *GossipSubRouter) sendPrune(p peer.ID, topic string) {
|
||||
}
|
||||
|
||||
func (gs *GossipSubRouter) sendRPC(p peer.ID, out *RPC) {
|
||||
// do we own the RPC?
|
||||
own := false
|
||||
|
||||
// piggyback cotrol message retries
|
||||
ctl, ok := gs.control[p]
|
||||
if ok {
|
||||
out = copyRPC(out)
|
||||
own = true
|
||||
gs.piggybackControl(p, out, ctl)
|
||||
delete(gs.control, p)
|
||||
}
|
||||
@ -318,6 +323,10 @@ func (gs *GossipSubRouter) sendRPC(p peer.ID, out *RPC) {
|
||||
// piggyback gossip
|
||||
ihave, ok := gs.gossip[p]
|
||||
if ok {
|
||||
if !own {
|
||||
out = copyRPC(out)
|
||||
own = true
|
||||
}
|
||||
gs.piggybackGossip(p, out, ihave)
|
||||
delete(gs.gossip, p)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user