From 4bb7dcaf646ac2f0faa1fb8af7bf477b96f0f881 Mon Sep 17 00:00:00 2001 From: Sanket Sudake Date: Wed, 20 Apr 2022 09:49:06 +0530 Subject: [PATCH] Check active request before decrease in functionCache (#2413) Signed-off-by: Sanket Sudake --- pkg/poolcache/poolcache.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/poolcache/poolcache.go b/pkg/poolcache/poolcache.go index d3ad1bc9..ddeb995b 100644 --- a/pkg/poolcache/poolcache.go +++ b/pkg/poolcache/poolcache.go @@ -155,9 +155,13 @@ func (c *Cache) service() { case markAvailable: if _, ok := c.cache[req.function]; ok { if _, ok = c.cache[req.function][req.address]; ok { - c.cache[req.function][req.address].activeRequests-- - if c.logger.Core().Enabled(zap.DebugLevel) { - otelUtils.LoggerWithTraceID(req.ctx, c.logger).Debug("Decrease active requests", zap.String("function", req.function.(string)), zap.String("address", req.address.(string)), zap.Int("activeRequests", c.cache[req.function][req.address].activeRequests)) + if c.cache[req.function][req.address].activeRequests > 0 { + c.cache[req.function][req.address].activeRequests-- + if c.logger.Core().Enabled(zap.DebugLevel) { + otelUtils.LoggerWithTraceID(req.ctx, c.logger).Debug("Decrease active requests", zap.String("function", req.function.(string)), zap.String("address", req.address.(string)), zap.Int("activeRequests", c.cache[req.function][req.address].activeRequests)) + } + } else { + otelUtils.LoggerWithTraceID(req.ctx, c.logger).Error("Invalid request to decrease active requests", zap.String("function", req.function.(string)), zap.String("address", req.address.(string)), zap.Int("activeRequests", c.cache[req.function][req.address].activeRequests)) } } }