[#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 <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-11-15 14:28:15 +03:00 committed by fyrchik
parent 56442c0be3
commit 27ca754dc1

View file

@ -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))