From 479c5a65e141f5418251124deb20de0b0f2c2424 Mon Sep 17 00:00:00 2001
From: Pavel Karpy
Date: Thu, 4 May 2023 19:44:49 +0300
Subject: [PATCH] [#322] node: Fix tree svc panic
If a connection has not been established earlier, it stores `nil` in LRU
cache. Cache eviction tries to close every connection (even a `nil` one) and
panics but not crash the app because we are using pools.
That ugly bug also leads to a deadlock where `Unlock` is not called via
`defer` func (and that is the way I found it).
Signed-off-by: Pavel Karpy
---
CHANGELOG.md | 1 +
pkg/services/tree/cache.go | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4c86fa37..60a5d7d92 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Changelog for FrostFS Node
- Take network settings into account during netmap contract update (#100)
- Read config files from dir even if config file not provided via `--config` for node (#238)
- Notary requests parsing according to `neo-go`'s updates (#268)
+- Tree service panic in its internal client cache (#322)
### Removed
### Updated
diff --git a/pkg/services/tree/cache.go b/pkg/services/tree/cache.go
index ab9f509ac..56b97e687 100644
--- a/pkg/services/tree/cache.go
+++ b/pkg/services/tree/cache.go
@@ -36,7 +36,9 @@ var errRecentlyFailed = errors.New("client has recently failed")
func (c *clientCache) init() {
l, _ := simplelru.NewLRU[string, cacheItem](defaultClientCacheSize, func(_ string, value cacheItem) {
- _ = value.cc.Close()
+ if conn := value.cc; conn != nil {
+ _ = conn.Close()
+ }
})
c.LRU = *l
}
--
2.45.2