1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Bugfix] Infinite loop fix in ArangoD AsyncClient (#1049)

This commit is contained in:
Adam Janikowski 2022-07-11 13:01:16 +02:00 committed by GitHub
parent 64201dfe4f
commit 5304ef8249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 2 deletions

View file

@ -29,6 +29,7 @@
- (Bugfix) Allow to remove resources (CPU & Memory) on the managed pods
- (Bugfix) Add DistributeShardsLike support
- (Feature) Member restarts metric
- (Bugfix) Infinite loop fix in ArangoD AsyncClient
## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07)
- (Bugfix) Fix arangosync members state inspection

View file

@ -35,7 +35,7 @@ func IsAsyncErrorNotFound(err error) bool {
return true
}
return IsAsyncErrorNotFound(errors.Cause(err))
return IsAsyncErrorNotFound(errors.CauseWithNil(err))
}
func newAsyncErrorNotFound(id string) error {
@ -61,7 +61,7 @@ func IsAsyncJobInProgress(err error) (string, bool) {
return v.jobID, true
}
return IsAsyncJobInProgress(errors.Cause(err))
return IsAsyncJobInProgress(errors.CauseWithNil(err))
}
func newAsyncJobInProgress(id string) error {

View file

@ -0,0 +1,37 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package conn
import (
"testing"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/stretchr/testify/require"
)
func Test_IsAsyncErrorNotFound_Loop(t *testing.T) {
require.False(t, IsAsyncErrorNotFound(errors.Newf("Error")))
}
func Test_IsAsyncJobInProgress_Loop(t *testing.T) {
_, ok := IsAsyncJobInProgress(errors.Newf("Error"))
require.False(t, ok)
}

View file

@ -45,6 +45,20 @@ var (
WithMessagef = errs.WithMessagef
)
// CauseWithNil returns Cause of an error.
// If error returned by Cause is same (no Causer interface implemented), function will return nil instead
func CauseWithNil(err error) error {
if nerr := Cause(err); err == nil {
return nil
} else if nerr == err {
// Cause returns same error if error object does not implement Causer interface
// To prevent infinite loops in usage CauseWithNil will return nil in this case
return nil
} else {
return nerr
}
}
func Newf(format string, args ...interface{}) error {
return New(fmt.Sprintf(format, args...))
}