Skip to content

Commit 5304ef8

Browse files
authored
[Bugfix] Infinite loop fix in ArangoD AsyncClient (#1049)
1 parent 64201df commit 5304ef8

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- (Bugfix) Allow to remove resources (CPU & Memory) on the managed pods
3030
- (Bugfix) Add DistributeShardsLike support
3131
- (Feature) Member restarts metric
32+
- (Bugfix) Infinite loop fix in ArangoD AsyncClient
3233

3334
## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07)
3435
- (Bugfix) Fix arangosync members state inspection

pkg/util/arangod/conn/async_errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func IsAsyncErrorNotFound(err error) bool {
3535
return true
3636
}
3737

38-
return IsAsyncErrorNotFound(errors.Cause(err))
38+
return IsAsyncErrorNotFound(errors.CauseWithNil(err))
3939
}
4040

4141
func newAsyncErrorNotFound(id string) error {
@@ -61,7 +61,7 @@ func IsAsyncJobInProgress(err error) (string, bool) {
6161
return v.jobID, true
6262
}
6363

64-
return IsAsyncJobInProgress(errors.Cause(err))
64+
return IsAsyncJobInProgress(errors.CauseWithNil(err))
6565
}
6666

6767
func newAsyncJobInProgress(id string) error {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package conn
22+
23+
import (
24+
"testing"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
27+
"github.com/stretchr/testify/require"
28+
)
29+
30+
func Test_IsAsyncErrorNotFound_Loop(t *testing.T) {
31+
require.False(t, IsAsyncErrorNotFound(errors.Newf("Error")))
32+
}
33+
34+
func Test_IsAsyncJobInProgress_Loop(t *testing.T) {
35+
_, ok := IsAsyncJobInProgress(errors.Newf("Error"))
36+
require.False(t, ok)
37+
}

pkg/util/errors/errors.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ var (
4545
WithMessagef = errs.WithMessagef
4646
)
4747

48+
// CauseWithNil returns Cause of an error.
49+
// If error returned by Cause is same (no Causer interface implemented), function will return nil instead
50+
func CauseWithNil(err error) error {
51+
if nerr := Cause(err); err == nil {
52+
return nil
53+
} else if nerr == err {
54+
// Cause returns same error if error object does not implement Causer interface
55+
// To prevent infinite loops in usage CauseWithNil will return nil in this case
56+
return nil
57+
} else {
58+
return nerr
59+
}
60+
}
61+
4862
func Newf(format string, args ...interface{}) error {
4963
return New(fmt.Sprintf(format, args...))
5064
}

0 commit comments

Comments
 (0)