nic-chen commented on code in PR #2650:
URL: https://github.com/apache/apisix-dashboard/pull/2650#discussion_r1006371114
##########
api/cmd/root.go:
##########
@@ -81,3 +89,57 @@ func manageAPI() error {
}
return nil
}
+
+func etcdConnectionChecker() context.CancelFunc {
+ ctx, cancel := context.WithCancel(context.TODO())
+ unavailableTimes := 0
+
+ go func() {
+ etcdClient := storage.GenEtcdStorage().GetClient()
+ for {
+ select {
+ case <-time.Tick(10 * time.Second):
+ sCtx, sCancel :=
context.WithTimeout(context.TODO(), 5*time.Second)
+ err := etcdClient.Sync(sCtx)
Review Comment:
oh, I think it is unnecessary. Because the client has a retry mechanism,
even if the connection is interrupted during operation, reusing the client will
automatically recover, only the `watch` cannot recover automatically in some
cases
##########
api/cmd/root.go:
##########
@@ -81,3 +89,57 @@ func manageAPI() error {
}
return nil
}
+
+func etcdConnectionChecker() context.CancelFunc {
+ ctx, cancel := context.WithCancel(context.TODO())
+ unavailableTimes := 0
+
+ go func() {
+ etcdClient := storage.GenEtcdStorage().GetClient()
+ for {
+ select {
+ case <-time.Tick(10 * time.Second):
+ sCtx, sCancel :=
context.WithTimeout(context.TODO(), 5*time.Second)
+ err := etcdClient.Sync(sCtx)
+ sCancel()
+ if err != nil {
+ unavailableTimes++
+ log.Errorf("etcd connection loss
detected, times: %d", unavailableTimes)
+ continue
+ }
+
+ // After multiple failures, the connection is
restored
+ if unavailableTimes >= 1 {
+ log.Warnf("etcd connection recovered,
but after several connection losses, reinitializing stores, times: %d",
unavailableTimes)
+ unavailableTimes = 0
+
+ // When this happens, force a full
re-initialization of the store
+ store.RangeStore(func(key store.HubKey,
store *store.GenericStore) bool {
+ log.Warnf("etcd store
reinitializing: resource: %s", key)
+ _ = store.Init()
Review Comment:
should also log the err
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]