This is an automated email from the ASF dual-hosted git repository.
monkeydluffy pushed a commit to branch release/3.0
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/release/3.0 by this push:
new 4133aa1f3 fix: memory leak when etcd watch failed (#2920)
4133aa1f3 is described below
commit 4133aa1f3c9ce62a5bed5ba8a9162888193ee455
Author: hauer <[email protected]>
AuthorDate: Mon Feb 19 15:24:38 2024 +0800
fix: memory leak when etcd watch failed (#2920)
---
api/internal/core/store/store.go | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/api/internal/core/store/store.go b/api/internal/core/store/store.go
index b75f406dd..638357565 100644
--- a/api/internal/core/store/store.go
+++ b/api/internal/core/store/store.go
@@ -63,6 +63,7 @@ type GenericStore struct {
cancel context.CancelFunc
closing bool
+ inited bool //is inited
}
type GenericStoreOption struct {
@@ -109,12 +110,20 @@ func ReInit() error {
return err
}
}
+
+ //clear storeNeedReInit
+ storeNeedReInit = storeNeedReInit[:0]
return nil
}
func (s *GenericStore) Init() error {
s.initLock.Lock()
defer s.initLock.Unlock()
+ //return if inited
+ if s.IsInited() {
+ return nil
+ }
+
return s.listAndWatch()
}
@@ -351,6 +360,7 @@ func (s *GenericStore) listAndWatch() error {
// start watch
s.cancel = s.watch()
+ s.SetIsInited(true)
return nil
}
@@ -362,7 +372,11 @@ func (s *GenericStore) watch() context.CancelFunc {
defer func() {
if !s.closing {
log.Errorf("etcd watch exception closed,
restarting: resource: %s", s.Type())
- storeNeedReInit = append(storeNeedReInit, s)
+ //only add to storeNeedReInit when from inited
to uninited
+ if s.IsInited() {
+ s.SetIsInited(false)
+ storeNeedReInit =
append(storeNeedReInit, s)
+ }
}
}()
defer runtime.HandlePanic()
@@ -421,3 +435,11 @@ func (s *GenericStore) GetObjStorageKey(obj interface{})
string {
func (s *GenericStore) GetStorageKey(key string) string {
return fmt.Sprintf("%s/%s", s.opt.BasePath, key)
}
+
+func (s *GenericStore) IsInited() bool {
+ return s.inited
+}
+
+func (s *GenericStore) SetIsInited(inited bool) {
+ s.inited = inited
+}