From 1779664644e4a1479980c175f84b748a0646303e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 15 Nov 2022 14:28:15 +0300 Subject: [PATCH] [#2058] services/policer: Fix panic in `shardPolicyWorker` ``` 2022/11/15 08:40:56 worker exits from a panic: runtime error: index out of range [0] with length 0 2022/11/15 08:40:56 worker exits from panic: goroutine 1188 [running]: github.com/panjf2000/ants/v2.(*goWorker).run.func1.1() github.com/panjf2000/ants/v2@v2.4.0/worker.go:58 +0x10c panic({0x1042b60, 0xc0015ae018}) runtime/panic.go:1038 +0x215 github.com/nspcc-dev/neofs-node/pkg/services/policer.(*Policer).shardPolicyWorker.func1() github.com/nspcc-dev/neofs-node/pkg/services/policer/process.go:65 +0x366 github.com/panjf2000/ants/v2.(*goWorker).run.func1() github.com/panjf2000/ants/v2@v2.4.0/worker.go:68 +0x97 created by github.com/panjf2000/ants/v2.(*goWorker).run github.com/panjf2000/ants/v2@v2.4.0/worker.go:48 +0x68 ``` Signed-off-by: Evgenii Stratonikov --- pkg/services/policer/process.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/services/policer/process.go b/pkg/services/policer/process.go index bab1b9e1..eb2ce8e1 100644 --- a/pkg/services/policer/process.go +++ b/pkg/services/policer/process.go @@ -47,25 +47,25 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) { case <-ctx.Done(): return default: - addr := addrs[i].Address - if p.objsInWork.inWork(addr) { + addr := addrs[i] + if p.objsInWork.inWork(addr.Address) { // do not process an object // that is in work continue } err = p.taskPool.Submit(func() { - v, ok := p.cache.Get(addr) + v, ok := p.cache.Get(addr.Address) if ok && time.Since(v.(time.Time)) < p.evictDuration { return } - p.objsInWork.add(addr) + p.objsInWork.add(addr.Address) - p.processObject(ctx, addrs[i]) + p.processObject(ctx, addr) p.cache.Add(addr, time.Now()) - p.objsInWork.remove(addr) + p.objsInWork.remove(addr.Address) }) if err != nil { p.log.Warn("pool submission", zap.Error(err))