Skip to content

Commit

Permalink
Fix file descriptor leaks in tlscfg unit tests (#2592)
Browse files Browse the repository at this point in the history
There are a few file descriptor leaks in the unit tests, and on an error
condition in certwatcher.

This is an issue when checking for flaky tests with
`go test -test.count ..`. One leak is in an error condition in
certwatcher but it is unlikely to be a runtime issue because.

Related #2586

Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>
  • Loading branch information
chlunde authored Oct 28, 2020
1 parent 884240d commit 8388432
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/config/tlscfg/cert_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func newCertWatcher(opts Options, logger *zap.Logger) (*certWatcher, error) {
return nil, err
}
if err := addCertsToWatch(watcher, opts); err != nil {
watcher.Close()
return nil, err
}
return &certWatcher{
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/tlscfg/cert_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func TestReload_err_watch(t *testing.T) {
func TestAddCertsToWatch_err(t *testing.T) {
watcher, err := fsnotify.NewWatcher()
require.NoError(t, err)
defer watcher.Close()

tests := []struct {
opts Options
Expand Down Expand Up @@ -323,6 +324,7 @@ func syncWrite(filename string, data []byte, perm os.FileMode) error {
if err != nil {
return err
}
defer f.Close()
if _, err = f.Write(data); err != nil {
return err
}
Expand Down

0 comments on commit 8388432

Please sign in to comment.