Commit 4f7a6228 authored by acud's avatar acud Committed by GitHub

fix(hive): prevent goroutine pileup on validation (#2444)

parent fe6a5919
...@@ -32,12 +32,13 @@ import ( ...@@ -32,12 +32,13 @@ import (
) )
const ( const (
protocolName = "hive" protocolName = "hive"
protocolVersion = "1.0.0" protocolVersion = "1.0.0"
peersStreamName = "peers" peersStreamName = "peers"
messageTimeout = 1 * time.Minute // maximum allowed time for a message to be read or written. messageTimeout = 1 * time.Minute // maximum allowed time for a message to be read or written.
maxBatchSize = 30 maxBatchSize = 30
pingTimeout = time.Second * 5 // time to wait for ping to succeed pingTimeout = time.Second * 5 // time to wait for ping to succeed
batchValidationTimeout = 5 * time.Minute // prevent lock contention on peer validation
) )
var ( var (
...@@ -246,7 +247,9 @@ func (s *Service) startCheckPeersHandler() { ...@@ -246,7 +247,9 @@ func (s *Service) startCheckPeersHandler() {
s.wg.Add(1) s.wg.Add(1)
go func() { go func() {
defer s.wg.Done() defer s.wg.Done()
s.checkAndAddPeers(ctx, newPeers) cctx, cancel := context.WithTimeout(ctx, batchValidationTimeout)
defer cancel()
s.checkAndAddPeers(cctx, newPeers)
}() }()
} }
} }
......
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