Skip to content

Commit 51622c8

Browse files
authored
[Bugfix] Fix After leaked GoRoutines (#1231)
1 parent 1992298 commit 51622c8

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Bugfix) Fix deployment creation on ARM64
55
- (DebugPackage) Add Agency Dump & State
6+
- (Bugfix) Fix After leaked GoRoutines
67

78
## [1.2.23](https://github.com/arangodb/kube-arangodb/tree/1.2.23) (2023-01-12)
89
- (Bugfix) Remove PDBs if group count is 0

pkg/util/timer/after.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ package timer
2323
import "time"
2424

2525
func After(duration time.Duration) <-chan time.Time {
26-
r := make(chan time.Time)
26+
r := make(chan time.Time, 1)
2727

2828
go func() {
2929
defer close(r)

pkg/util/timer/after_leak_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 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 timer
22+
23+
import (
24+
"runtime"
25+
"testing"
26+
"time"
27+
28+
"github.com/stretchr/testify/require"
29+
)
30+
31+
func checkGoRoutinesLeak(t *testing.T, f func()) {
32+
got := runtime.NumGoroutine()
33+
34+
f()
35+
36+
require.Equal(t, got, runtime.NumGoroutine())
37+
}
38+
39+
func Test_AfterLeaks(t *testing.T) {
40+
checkGoRoutinesLeak(t, func() {
41+
After(time.Second)
42+
43+
time.Sleep(5 * time.Second)
44+
})
45+
}

0 commit comments

Comments
 (0)