[#156] services/tree: Pass context to replicationWorker()

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
fix/139-unit_test_storage
Evgenii Stratonikov 2023-03-21 16:58:49 +03:00 committed by Gitea
parent 5368c4207a
commit 3f6b962349
1 changed files with 4 additions and 5 deletions

View File

@ -52,7 +52,7 @@ func (s *Service) localReplicationWorker() {
} }
} }
func (s *Service) replicationWorker() { func (s *Service) replicationWorker(ctx context.Context) {
for { for {
select { select {
case <-s.closeCh: case <-s.closeCh:
@ -64,13 +64,13 @@ func (s *Service) replicationWorker() {
task.n.IterateNetworkEndpoints(func(addr string) bool { task.n.IterateNetworkEndpoints(func(addr string) bool {
lastAddr = addr lastAddr = addr
c, err := s.cache.get(context.Background(), addr) c, err := s.cache.get(ctx, addr)
if err != nil { if err != nil {
lastErr = fmt.Errorf("can't create client: %w", err) lastErr = fmt.Errorf("can't create client: %w", err)
return false return false
} }
ctx, cancel := context.WithTimeout(context.Background(), s.replicatorTimeout) ctx, cancel := context.WithTimeout(ctx, s.replicatorTimeout)
_, lastErr = c.Apply(ctx, task.req) _, lastErr = c.Apply(ctx, task.req)
cancel() cancel()
@ -94,8 +94,7 @@ func (s *Service) replicationWorker() {
func (s *Service) replicateLoop(ctx context.Context) { func (s *Service) replicateLoop(ctx context.Context) {
for i := 0; i < s.replicatorWorkerCount; i++ { for i := 0; i < s.replicatorWorkerCount; i++ {
//nolint: contextcheck go s.replicationWorker(ctx)
go s.replicationWorker()
go s.localReplicationWorker() go s.localReplicationWorker()
} }
defer func() { defer func() {