From 3f6b96234904debb46759b18e04e6adf2683c7fe Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 21 Mar 2023 16:58:49 +0300 Subject: [PATCH] [#156] services/tree: Pass context to replicationWorker() Signed-off-by: Evgenii Stratonikov --- pkg/services/tree/replicator.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index 8a1180289..bb20310b2 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -52,7 +52,7 @@ func (s *Service) localReplicationWorker() { } } -func (s *Service) replicationWorker() { +func (s *Service) replicationWorker(ctx context.Context) { for { select { case <-s.closeCh: @@ -64,13 +64,13 @@ func (s *Service) replicationWorker() { task.n.IterateNetworkEndpoints(func(addr string) bool { lastAddr = addr - c, err := s.cache.get(context.Background(), addr) + c, err := s.cache.get(ctx, addr) if err != nil { lastErr = fmt.Errorf("can't create client: %w", err) return false } - ctx, cancel := context.WithTimeout(context.Background(), s.replicatorTimeout) + ctx, cancel := context.WithTimeout(ctx, s.replicatorTimeout) _, lastErr = c.Apply(ctx, task.req) cancel() @@ -94,8 +94,7 @@ func (s *Service) replicationWorker() { func (s *Service) replicateLoop(ctx context.Context) { for i := 0; i < s.replicatorWorkerCount; i++ { - //nolint: contextcheck - go s.replicationWorker() + go s.replicationWorker(ctx) go s.localReplicationWorker() } defer func() {