diff --git a/portalnetwork/beacon/beacon_network.go b/portalnetwork/beacon/beacon_network.go index f097697f7ae7..0a2316400aeb 100644 --- a/portalnetwork/beacon/beacon_network.go +++ b/portalnetwork/beacon/beacon_network.go @@ -240,12 +240,20 @@ func (bn *BeaconNetwork) processContentLoop(ctx context.Context) { bn.log.Error("validate content failed", "err", err) continue } - gossippedNum, err := bn.portalProtocol.Gossip(&contentElement.Node, contentElement.ContentKeys, contentElement.Contents) - bn.log.Trace("gossippedNum", "gossippedNum", gossippedNum) - if err != nil { - bn.log.Error("gossip failed", "err", err) - continue - } + go func(ctx context.Context) { + select { + case <-ctx.Done(): + return + default: + var gossippedNum int + gossippedNum, err = bn.portalProtocol.Gossip(&contentElement.Node, contentElement.ContentKeys, contentElement.Contents) + bn.log.Trace("gossippedNum", "gossippedNum", gossippedNum) + if err != nil { + bn.log.Error("gossip failed", "err", err) + return + } + } + }(ctx) } } } diff --git a/portalnetwork/history/history_network.go b/portalnetwork/history/history_network.go index dc0293a97661..6d72a12f0f6f 100644 --- a/portalnetwork/history/history_network.go +++ b/portalnetwork/history/history_network.go @@ -508,12 +508,21 @@ func (h *HistoryNetwork) processContentLoop(ctx context.Context) { h.log.Error("validate content failed", "err", err) continue } - gossippedNum, err := h.portalProtocol.Gossip(&contentElement.Node, contentElement.ContentKeys, contentElement.Contents) - h.log.Trace("gossippedNum", "gossippedNum", gossippedNum) - if err != nil { - h.log.Error("gossip failed", "err", err) - continue - } + + go func(ctx context.Context) { + select { + case <-ctx.Done(): + return + default: + var gossippedNum int + gossippedNum, err = h.portalProtocol.Gossip(&contentElement.Node, contentElement.ContentKeys, contentElement.Contents) + h.log.Trace("gossippedNum", "gossippedNum", gossippedNum) + if err != nil { + h.log.Error("gossip failed", "err", err) + return + } + } + }(ctx) } } }